I got this module
defmodule MapSetBug do
@vars [
%{one: 1, two: MapSet.new(["a", "b", "c"])},
%{one: 2, two: MapSet.new(["a", "b", "c"])},
%{one: 3, two: MapSet.new(["a", "b", "c"])}
]
@map_set Enum.flat_map(@vars, fn var ->
Enum.map(var.two, &{var.one, &1})
end)
|> MapSet.new()
def valid(one, two) do
MapSet.member?(@map_set, {one, two})
end
end
Which gives me this error:
lib/map_set_bug.ex:13:no_return
Function valid/2 has no local return.
________________________________________________________________________________
lib/map_set_bug.ex:14:call_without_opaque
The call MapSet.member?(#{'__struct__':='Elixir.MapSet', 'map':=#{{1 | 2 | 3,<<_:8>>}=>[]}, 'version':=2},{_,_}) does not have an opaque term of type 'Elixir.MapSet':t(_) in 1st.
________________________________________________________________________________
done (warnings were emitted)
I am unable to resolve it. But this:
defmodule MapSetBug do
@map_set MapSet.new()
def valid(x) do
MapSet.member?(@map_set, x)
end
end
Gives the same kind of error:
lib/map_set_bug.ex:4:no_return
Function valid/1 has no local return.
________________________________________________________________________________
lib/map_set_bug.ex:5:call_without_opaque
The call MapSet.member?(#{'__struct__'=>'Elixir.MapSet', 'map'=>#{}, 'version'=>2},_x@1::any()) does not have an opaque term of type 'Elixir.MapSet':t(_) in 1st.
________________________________________________________________________________
Now⊠is it a dialyzer bug? MapSet specs bug? Or my code bug?
Of course this:
defmodule MapSetBug do
def map_set do
MapSet.new()
end
def valid(x) do
MapSet.member?(map_set(), x)
end
end
Gives no dialyzer error, but thatâs not something I want to achieve. I need that MapSet created once at compile time, and not every time a function is called.