Skip to content

Commit eb8bbc9

Browse files
authored
Fix map difference union optimization (#15319)
1 parent c533223 commit eb8bbc9

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/elixir/lib/module/types/descr.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3062,7 +3062,8 @@ defmodule Module.Types.Descr do
30623062
#
30633063
# Outside of this particular scenario, the `a_int` optimization has been useful,
30643064
# but we haven't measured benefits for `a_union`.
3065-
defp map_leaf_difference(bdd_leaf(tag, fields), bdd_leaf(:open, [{key, v2}]), type) do
3065+
defp map_leaf_difference(bdd_leaf(tag, fields), bdd_leaf(:open, [{key, v2}]), type)
3066+
when type != :union do
30663067
{found?, v1} =
30673068
case fields_find(key, fields) do
30683069
{:ok, value} -> {true, value}

lib/elixir/test/elixir/module/types/descr_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ defmodule Module.Types.DescrTest do
608608
assert difference(closed_map(a: integer()), open_map(b: if_set(integer()))) == none()
609609
end
610610

611+
test "map double negation with redundant empty map" do
612+
type = closed_map(a: atom()) |> union(open_map(a: if_set(integer()))) |> union(empty_map())
613+
614+
assert negation(negation(type)) |> equal?(type)
615+
end
616+
611617
test "map (struct optimizations)" do
612618
# We do direct assertions because we want to check how it works underneath
613619
atom_foo = atom([:foo])

0 commit comments

Comments
 (0)