Skip to content

Commit 20cac29

Browse files
committed
Avoid adding lists that match negations
1 parent f4fdf64 commit 20cac29

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,17 +1879,14 @@ defmodule Module.Types.Descr do
18791879
acc ->
18801880
inter = intersection(list_type1, list_type2)
18811881
last = intersection(last_type1, last_type2)
1882+
negs = negs1 ++ negs2
18821883

1883-
if empty?(inter) or empty?(last) do
1884-
acc
1885-
else
1886-
[{inter, last, negs1 ++ negs2} | acc]
1884+
cond do
1885+
:lists.member({inter, last}, negs) -> acc
1886+
empty?(inter) or empty?(last) -> acc
1887+
true -> [{inter, last, negs} | acc]
18871888
end
18881889
end
1889-
|> case do
1890-
[] -> 0
1891-
dnf -> dnf
1892-
end
18931890
end
18941891

18951892
# Computes the difference between two DNF (Disjunctive Normal Form) list types.
@@ -1902,7 +1899,7 @@ defmodule Module.Types.Descr do
19021899
# 3. Base case: adds dnf2 type to negations of dnf1 type
19031900
# The result may be larger than the initial dnf1, which is maintained in the accumulator.
19041901
defp list_difference(_, dnf) when dnf == @non_empty_list_top do
1905-
0
1902+
[]
19061903
end
19071904

19081905
defp list_difference(dnf1, dnf2) do
@@ -1916,7 +1913,12 @@ defmodule Module.Types.Descr do
19161913
Enum.reduce(negs2, [], fn {nt, nlast}, nacc ->
19171914
t = intersection(t1, nt)
19181915
last = intersection(last1, nlast)
1919-
if empty?(t) or empty?(last), do: nacc, else: [{t, last, negs1} | nacc]
1916+
1917+
cond do
1918+
:lists.member({t, last}, negs1) -> nacc
1919+
empty?(t) or empty?(last) -> nacc
1920+
true -> [{t, last, negs1} | nacc]
1921+
end
19201922
end)
19211923

19221924
i = intersection(t1, t2)

0 commit comments

Comments
 (0)