On Elixir 1.6.2, Dialyzer doesn’t seem to be reporting an issue when calling an anonymous function with incorrect arguments. Here’s a quick example:
@type cool_fn :: (String.t(), :a | :b -> String.t())
@spec cool(String.t(), :a | :b) :: String.t()
def cool(name, aorb), do: name <> "- #{aorb}"
@spec cool_doer(cool_fn) :: String.t()
def cool_doer(cool_fun \\ &cool/2) do
cool_fun.("hi", :c)
end
When used like above, dialyzer doesn’t report the incorrect :c
argument passed to the anonymous function.
If I change the call inside cool_doer/1
to just directly call cool("hi", :c)
(and not the passed-in anonymous function), I do get dialyzer warnings.
Is there something I’m missing or doing wrong that’s causing this to not be caught by dialyzer?
Additionally, is there any way to have the (String.t(), :a | :b -> String.t())
function signature “shared” between the @type
and @spec
specs?