How to make Dialyzer more strict?

I had a similar question in this post and got a nice answer from @peerreynders.

You could do

  @type good_hello() :: map() 
  @type bad_hello() :: map() 

  @spec hello(integer()) :: good_hello() | bad_hello()
  def hello(int) do
    case int do
      1 -> good()
      _ -> bad()
    end
  end

  @spec good() :: good_hello()
  def good(), do: %{hello: "world"}

  @spec bad() :: bad_hello()
  def bad(), do: :wtf

This way You would catch spec error with dialyzer.

5 Likes