Skip to content

Commit f3dfb72

Browse files
committed
Properly handle optional keys in map intersection
1 parent 7e14961 commit f3dfb72

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
@@ -1329,11 +1329,10 @@ defmodule Module.Types.Descr do
13291329
:maps.next(iterator) |> map_literal_intersection_loop(acc)
13301330

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

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

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

166+
assert intersection(closed_map(a: integer()), open_map(b: if_set(integer()))) ==
167+
closed_map(a: integer())
168+
166169
assert equal?(
167170
intersection(closed_map(a: integer()), closed_map(a: if_set(integer()))),
168171
closed_map(a: integer())

0 commit comments

Comments
 (0)