I've noticed that Dialyzer possibly simplifies long union types, at least when it comes to atoms.
For example, if I have:
defmodule Foo do
@type name() :: :one | :two | :three
@spec bar(name()) :: String.t()
def bar(name), do: to_string(name)
end
and then I call the function with
Foo.bar(:hello)
Dialyzer will catch the error saying that :hello
is a wrong type for this function.
But then, if I change the type declaration to make the union consist of more than 13 (my observation) items (pseudo code):
@type name() :: :one | :two | :three ... :fourteen
Dialyzer seems to convert it into a simple atom()
type under the hood and would not complain about calling Foo.bar/1
with any atom, even if it's not included into the union.
So I wonder if that's expected behaviour and whether there's a way to prevent that?