Skip to content

Commit 4ad3e0a

Browse files
committed
Fix map_difference_strategy with optional keys
1 parent a5e83eb commit 4ad3e0a

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,11 +4402,11 @@ defmodule Module.Types.Descr do
44024402
end
44034403
end
44044404

4405-
defp map_difference_strategy([{k1, _} | _], [{k2, _} | _], tag1, _tag2, _status)
4405+
defp map_difference_strategy([{k1, _} | _], [{k2, value} | _], tag1, _tag2, _status)
44064406
when k1 > k2 do
44074407
# Right side has a key the left side does not have,
44084408
# if left-side is closed, they are disjoint.
4409-
if tag1 == :closed, do: :disjoint, else: :none
4409+
if tag1 == :closed and not is_optional_static(value), do: :disjoint, else: :none
44104410
end
44114411

44124412
defp map_difference_strategy([{_, v} | t1], [{_, v} | t2], tag1, tag2, status) do
@@ -4445,9 +4445,6 @@ defmodule Module.Types.Descr do
44454445

44464446
defp map_difference_strategy(_l1, l2, tag1, tag2, status) do
44474447
cond do
4448-
tag1 == :closed and l2 != [] ->
4449-
:disjoint
4450-
44514448
tag2 == :open and l2 == [] ->
44524449
case status do
44534450
:all_equal ->
@@ -4458,11 +4455,11 @@ defmodule Module.Types.Descr do
44584455

44594456
:left_subtype_of_right ->
44604457
:left_subtype_of_right
4461-
4462-
_ ->
4463-
:none
44644458
end
44654459

4460+
tag1 == :closed and l2 != [] and Enum.all?(l2, fn {_, v} -> not is_optional_static(v) end) ->
4461+
:disjoint
4462+
44664463
true ->
44674464
:none
44684465
end

0 commit comments

Comments
 (0)