Skip to content

Commit 67b6f89

Browse files
committed
Do not add duplicates on maps and tuples intersections
1 parent 1637dc7 commit 67b6f89

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,16 @@ defmodule Module.Types.Descr do
12891289
acc ->
12901290
try do
12911291
{tag, fields} = map_literal_intersection(tag1, pos1, tag2, pos2)
1292-
[{tag, fields, negs1 ++ negs2} | acc]
1292+
entry = {tag, fields, negs1 ++ negs2}
1293+
1294+
# Imagine a, b, c, where a is closed and b and c are open with
1295+
# no keys in common. The result in both cases will be a and we
1296+
# want to avoid adding duplicates, especially as intersection
1297+
# is a cartesian product.
1298+
case :lists.member(entry, acc) do
1299+
true -> acc
1300+
false -> [entry | acc]
1301+
end
12931302
catch
12941303
:empty -> acc
12951304
end
@@ -1966,8 +1975,16 @@ defmodule Module.Types.Descr do
19661975
reduce: [] do
19671976
acc ->
19681977
case tuple_literal_intersection(tag1, elements1, tag2, elements2) do
1969-
{tag, fields} -> [{tag, fields, negs1 ++ negs2} | acc]
1970-
:empty -> acc
1978+
{tag, elements} ->
1979+
entry = {tag, elements, negs1 ++ negs2}
1980+
1981+
case :lists.member(entry, acc) do
1982+
true -> acc
1983+
false -> [entry | acc]
1984+
end
1985+
1986+
:empty ->
1987+
acc
19711988
end
19721989
end
19731990
|> case do

0 commit comments

Comments
 (0)