Dialyzer complaint about MapSet.member not getting proper type as argument, possible specs bug in MapSet

Again, due to the way how module attributes work, dialyzer can not know that you did MapSet.new(), it just “sees” %MapSet{…} inmidst of the code. And then it complaints rightfully.

Yes, the situation is not ideal, but it is like it is.

2 Likes

To illustrate this more extensively:

  @allow_list MapSet.new(["a", "b"])
  defp allow_listed?(identity) do
    MapSet.member?(@allow_list, identity)
  end

To dialyzer that looks like this:

  defp allow_listed?(identity) do
    MapSet.member?(%MapSet{map: %{"a" => [], "b" => []}}, identity)
  end

and not like this:

  defp allow_listed?(identity) do
    MapSet.member?(MapSet.new(["a", "b"]), identity)
  end
4 Likes

I just tried on Elixir 1.14 and it seems that the opaque warning is not appearing anymore, probably thanks to this typespec fix:
Change MapSet.t definition to make Dialyzer happy by michallepicki · Pull Request #11917 · elixir-lang/elixir · GitHub.

4 Likes