/dialyzer_example

Demo for Dialyzer issue

Primary LanguageElixir

Dialyzer issue demo

This project demonstrates an unusual Dialyzer failure, where generated clauses that can't match still trigger errors.

Running mix dialyzer on either master or phoenix-1.5 will give the following error:

Jones-MBP:blog_umbrella mattjones$ mix dialyzer
==> blog_web
Compiling 2 files (.ex)
Finding suitable PLTs
Checking PLT...
[:asn1, :blog, :compiler, :connection, :cowboy, :cowlib, :crypto, :db_connection, :decimal, :ecto, :ecto_sql, :eex, :elixir, :ex_unit, :file_system, :gettext, :jason, :kernel, :logger, :mime, :mix, :phoenix, :phoenix_ecto, :phoenix_html, :phoenix_live_dashboard, :phoenix_live_reload, :phoenix_live_view, :phoenix_pubsub, :plug, :plug_cowboy, :plug_crypto, :postgrex, :public_key, :ranch, :runtime_tools, :ssl, :stdlib, :telemetry, :telemetry_metrics, :telemetry_poller]
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/mattjones/src/blog_umbrella/_build/dev/dialyxir_erlang-22.2.4_elixir-1.10.0_deps-dev.plt',
  files: ['/Users/mattjones/src/blog_umbrella/_build/dev/lib/blog/ebin/Elixir.Blog.Application.beam',
   '/Users/mattjones/src/blog_umbrella/_build/dev/lib/blog/ebin/Elixir.Blog.Repo.beam',
   '/Users/mattjones/src/blog_umbrella/_build/dev/lib/blog/ebin/Elixir.Blog.beam',
   '/Users/mattjones/src/blog_umbrella/_build/dev/lib/blog_web/ebin/Elixir.BlogWeb.Application.beam',
   '/Users/mattjones/src/blog_umbrella/_build/dev/lib/blog_web/ebin/Elixir.BlogWeb.Endpoint.beam',
   ...],
  warnings: [:race_conditions, :no_undefined_callbacks, :unknown]
]
Total errors: 1, Skipped: 0, Unnecessary Skips: 0
done in 0m1.99s
lib/blog_web/controllers/page_controller.ex:1:pattern_match
The pattern can never match the type.

Pattern:
_ = %Plug.Conn{:halted => true}

Type:
%{:halted => false, _ => _}

________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

The offending clause is generated by Plug.Builder:

https://github.com/elixir-plug/plug/blob/4a34b4c5772b2a0249d7a18e948aa05e7de94166/lib/plug/builder.ex#L352-L354

But that should be subsequently marked as generated: true right below the quote block.

In my production app, this happens in one controller file without any explicit setting of halted: false, but I haven't been able to reproduce that in isolation.