Skip to content

Commit 64c4ecf

Browse files
committed
Do not add duplicates on maps and tuples intersections
1 parent ef002e2 commit 64c4ecf

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Diff for: lib/elixir/lib/module/types/descr.ex

+20-3
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,16 @@ defmodule Module.Types.Descr do
12751275
acc ->
12761276
try do
12771277
{tag, fields} = map_literal_intersection(tag1, pos1, tag2, pos2)
1278-
[{tag, fields, negs1 ++ negs2} | acc]
1278+
entry = {tag, fields, negs1 ++ negs2}
1279+
1280+
# Imagine a, b, c, where a is closed and b and c are open with
1281+
# no keys in common. The result in both cases will be a and we
1282+
# want to avoid adding duplicates, especially as intersection
1283+
# is a cartesian product.
1284+
case :lists.member(entry, acc) do
1285+
true -> acc
1286+
false -> [entry | acc]
1287+
end
12791288
catch
12801289
:empty -> acc
12811290
end
@@ -1931,8 +1940,16 @@ defmodule Module.Types.Descr do
19311940
reduce: [] do
19321941
acc ->
19331942
case tuple_literal_intersection(tag1, elements1, tag2, elements2) do
1934-
{tag, fields} -> [{tag, fields, negs1 ++ negs2} | acc]
1935-
:empty -> acc
1943+
{tag, elements} ->
1944+
entry = {tag, elements, negs1 ++ negs2}
1945+
1946+
case :lists.member(entry, acc) do
1947+
true -> acc
1948+
false -> [entry | acc]
1949+
end
1950+
1951+
:empty ->
1952+
acc
19361953
end
19371954
end
19381955
|> case do

0 commit comments

Comments
 (0)