You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defmoduleReprodo# pop an element from a non-empty mapdefpop(map,key)whenmap_size(map)>0do{_value,rest}=Map.pop!(map,key)rest==%{}enddeftestdomap=%{"some_key"=>1}pop(map,"some_key")endend
Generates the following compiler output:
warning: comparison between distinct types found:
rest == %{}
given types:
dynamic(map() and not empty_map()) == empty_map()
where "rest" was given the type:
# type: dynamic(map() and not empty_map())
# from: bug.ex:3:20
{_value, rest} = Map.pop!(map, key)
While Elixir can compare across all types, you are comparing across types which are always disjoint, and the result is either always true or always false
type warning found at:
│
4 │ rest == %{}
│ ~
│
└─ bug.ex:4:10: Repro.pop/2
Expected behavior
The compiler correctly marks the type of the map value as dynamic(map() and not empty_map()), but after calling Map.pop!/2 the type of rest can be empty_map(), so I think the right type is supposed to be just map().
I have found this PR: #15326, but I do not think they are the same. This one is for a tautological guard (checking a map size is bigger or equal to 0), and this one is not.
Activity
josevalim commentedon Jun 15, 2026
These are more isolated tests:
Fix map domain update