Skip to content

Commit 1f9256a

Browse files
committed
Properly handle optional keys in map intersection
1 parent ed2ff6a commit 1f9256a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,11 +1330,10 @@ defmodule Module.Types.Descr do
13301330
:maps.next(iterator) |> map_literal_intersection_loop(acc)
13311331

13321332
_ ->
1333-
# If the key is marked as not_set in the open map, we can ignore it.
1334-
if type1 == @not_set do
1335-
:maps.next(iterator) |> map_literal_intersection_loop(acc)
1336-
else
1337-
throw(:empty)
1333+
# If the key is optional in the open map, we can ignore it
1334+
case type1 do
1335+
%{optional: 1} -> :maps.next(iterator) |> map_literal_intersection_loop(acc)
1336+
_ -> throw(:empty)
13381337
end
13391338
end
13401339
end

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ defmodule Module.Types.DescrTest do
167167
assert intersection(closed_map(a: integer()), open_map(b: not_set())) ==
168168
closed_map(a: integer())
169169

170+
assert intersection(closed_map(a: integer()), open_map(b: if_set(integer()))) ==
171+
closed_map(a: integer())
172+
170173
assert equal?(
171174
intersection(closed_map(a: integer()), closed_map(a: if_set(integer()))),
172175
closed_map(a: integer())

0 commit comments

Comments
 (0)