Should dialyzer detect obvious type errors?

I am running VSCode with ElixirLS / Dialyzer. I would expect the following code in a module to cause some sort of warning but I am not seeing anything, is this expected behavior for dialyzer or potentially something is misconfigured?

def test() do
   # no warnings being displayed
   x = add("a", "b")
   y = add(%{}, nil)
   x + y
end

@spec add(integer, integer) :: integer
def add(a, b) do
   a + b
end

Dialyzer does detect those.

Check the configuration of your plugin, as Dialyzer is probably disabled.

lib/foo.ex:5:no_return
Function test/0 has no local return.

Sorry updated the example, that error is related to test(), nothing to do with the wrong types being passed into add

This is the full output

lib/dialyzer_test.ex:19:no_return
Function test/0 has no local return.
________________________________________________________________________________
lib/dialyzer_test.ex:21:call
The function call will not succeed.

DialyzerTest.add(<<97>>, <<98>>)

will never return since the success typing is:
(number(), number()) :: number()

and the contract is
(integer(), integer()) :: integer()

What are your Elixir and Erlang versions? If Erlang 24+ and Elixir older than 1.13 it may be related to missing line numbers for literals

2 Likes

Elixir 1.12.3 (compiled with Erlang/OTP 22)

Do you recommend I upgrade?

Elixir 1.12.3 (compiled with Erlang/OTP 22)

Even though your Elixir version was compiled with Erlang 22, you could be running it on a different Erlang version. Do you know what is your Erlang version? If it’s 24 then my theory can be right

If you’re on Erlang 24, the two things to try are to either upgrade Elixir to the current 1.13 RC version, or downgrade Erlang one of 23 versions. What is possible depends on which of the latest features your project / environment needs. Because (currently) Elixir 1.13 support in ElixirLS and the VSCode extension is in progress, if you rely on that editor integration, you may choose to downgrade Erlang for now. Editor support for Elixir 1.13 will catch up in some time soon

1 Like

Ok perfect, I am running Erlang 24 so I will downgrade to 23 and see if that fixes things

1 Like

I confirmed it works correctly with elixir 1.13 and Erlang 24

2 Likes