Dialyzer warning about Unknown types: Elixir.Atom.t etc

Dialyzer is complaining about Elixir types like Atom.t

$ mix dialyzer
Compiling 1 file (.ex)
...
  Proceeding with analysis...
Unknown types:
  'Elixir.Atom':t/0
 done in 0m1.72s
done (passed successfully)

(In a real program, its also complaining about my use of other types, like List.t, Boolean.t, etc).

If I replace Atom.t with atom() - then it works.
I noticed also that the source for the Atom module does not include a typespec, as I assume Elixr is substituting Atom.t with atom() automatically, but Dialzer does not know about that. That seems like bad news, and I hope I am wrong, or that there is some easy way to suppress these warnings, because to edit my code and put atom() etc all the way through the specs, seems like the wrong thing to be doing,
Following is the simple test source:

defmodule Test do
  @spec test() :: Atom.t
  def test() do
    :ok
  end
end

And the mix.exs:

defmodule Test.Mixfile do
  use Mix.Project

  def project do
    [app: :test,
     version: "0.1.0",
     elixir: "~> 1.4-rc",
     deps: deps()
    ]
  end

  def application do
    []
  end

  defp deps do
    [{:dialyxir, "~> 0.4", only: [:dev], runtime: false}]
  end
end

Full output:

$ mix dialyzer
Compiling 1 file (.ex)
Generated test app
Checking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
Finding suitable PLTs
Looking up modules in dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt
Looking up modules in dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1.plt
Finding applications for dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1.plt
Finding modules for dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1.plt
Checking 380 modules in dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1.plt
Finding applications for dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt
Finding modules for dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt
Copying dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1.plt to dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt
Looking up modules in dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt
Checking 380 modules in dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt
Adding 57 modules to dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt
Starting Dialyzer
dialyzer --no_check_plt --plt /home/brian/Development/test/test/_build/dev/dialyxir_erlang-19.1.5_elixir-1.4.0-rc.1_deps-dev.plt /home/brian/Development/test/test/_build/dev/lib/test/ebin
  Proceeding with analysis...
Unknown types:
  'Elixir.Atom':t/0
 done in 0m1.72s
done (passed successfully)

Using Dialyxir 0.4.1, Dialyzer 3.0.2 on Ubuntu, with ELixir v1.4 and Erlang

$ uname -a
Linux brian-B85M-HD3-A 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ grep version deps/dialyxir/mix.exs 
      version: "0.4.1",
$ dialyzer --version
Dialyzer version v3.0.2
$ iex --version
Erlang/OTP 19 [erts-8.1] [source-e7be63d] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

IEx 1.4.0-rc.1 (9c734ac)
$ erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 8.1
1 Like

This is where String.t is defined:

defmodule String do

   # ...*snip*
  @type t :: binary
  # ... *snip*
end

I believe that String.t exists mainly because the built-in string() would in fact refer to a charlist, while in Elixir we like working with binaries (See the note in the discussion).

Elixir does not replace the types automatically, it only happens when a type alias is present.

Most other modules that were made for the built-in types (They are mainly used when building protocol implementations for built-in types) do not offer such a @type t :: mybuiltintype type alias, which is the reason that Dyalizer indeed cannot find it.

2 Likes

Thanks for the reply, yes String.t was not being complained about, though its equivalent to binary()

Do you know is there any way to simply suppress warnings about specific types? Or should I just put up with it?

1 Like

Well, if it is code you wrote yourself, I’d suggest simply changing Atom.t to atom().

If it is code in a dependency that is being checked, I’m not sure if there is a way to suppress the warning (Other than not running dyalizer at all, of course). In both cases, you can ‘just put up with it’ because in the end, in Elixir the specs are optional; the code will work (or crash) with or without them.

2 Likes