Skip to content

Commit 89e0106

Browse files
authored
Fix map union optimization for open maps (#15322)
1 parent e39a1ca commit 89e0106

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,8 +3000,12 @@ defmodule Module.Types.Descr do
30003000
end
30013001
end
30023002

3003-
defp map_union_strategy([], [], _tag1, _tag2, status) do
3004-
status
3003+
defp map_union_strategy([], [], tag1, tag2, status) do
3004+
case status do
3005+
:left_subtype_of_right when tag1 == :open and tag2 == :closed -> :none
3006+
:right_subtype_of_left when tag1 == :closed and tag2 == :open -> :none
3007+
_ -> status
3008+
end
30053009
end
30063010

30073011
defp map_union_strategy(l1, l2, tag1, tag2, status) do

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ defmodule Module.Types.DescrTest do
115115
a_integer_open = open_map(a: integer())
116116
assert equal?(union(closed_map(a: integer()), a_integer_open), a_integer_open)
117117

118+
closed = closed_map(a: integer(), b: atom())
119+
open = open_map(a: integer(), b: boolean())
120+
121+
assert subtype?(closed, union(closed, open))
122+
assert subtype?(open, union(closed, open))
123+
assert subtype?(closed, union(open, closed))
124+
assert subtype?(open, union(open, closed))
125+
118126
# Domain key types
119127
atom_to_atom = open_map([{domain_key(:atom), atom()}])
120128
atom_to_integer = open_map([{domain_key(:atom), integer()}])

0 commit comments

Comments
 (0)