jeremyjh / dialyxir

Mix tasks to simplify use of Dialyzer in Elixir projects.
Apache License 2.0
1.69k stars 141 forks source link

Any way to get filename for the `Unknown type` errors? #426

Closed jisaacstone closed 3 years ago

jisaacstone commented 3 years ago

Environment

Current behavior

If I have a type in a @spec, but for get to alias, import, require, etc the module, the error message returned has no way to determine the file or line the error occurred on. This is a problem for example right now I got done with a refactor that touched ~30 files and I missed an alias somewhere, but I have no idea where.

Expected behavior

to reproduce

mix.exs

defmodule Test.MixProject do
  use Mix.Project

  def project do
    [
      app: :test,
      version: "0.1.0",
      elixir: "~> 1.10",
      dialyzer: [
        flags: [:unmatched_returns, :error_handling, :race_conditions, :unknown],
      ],
      deps: deps()
    ]
  end

  def application, do: []

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

lib/text.ex

defmodule Test do
  @spec hello(arg: Foo.t) :: {Foo.t, atom}
  def hello(arg) do
    {arg, :world}
  end
end
$ mix dialyzer
Finding suitable PLTs
Checking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
PLT is up to date!
No :ignore_warnings opt specified in mix.exs and default does not exist.

Starting Dialyzer
[
  check_plt: false,
  init_plt: '/Users/larpy/game/test/_build/dev/dialyxir_erlang-23.0.3_elixir-1.10.4_deps-dev.plt',
  files: ['/Users/larpy/game/test/_build/dev/lib/test/ebin/Elixir.Test.beam'],
  warnings: [:unmatched_returns, :error_handling, :race_conditions, :unknown,
   ...]
]
Total errors: 1, Skipped: 0, Unnecessary Skips: 0
done in 0m1.21s
:0:unknown_type
Unknown type: Foo.t/0.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2
asummers commented 3 years ago

Any work here would have to be in dialyzer.erl in OTP itself. We forward what information we get faithfully, but dialyzer itself drops this at the door before it even gets to dialyxir.

FWIW, I would be ecstatic with such an improvement upstream; this is one of the more annoying things to track down, particularly when retrofitting dialyzer onto an existing project.