Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/elixir/lib/module/types/descr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5278,6 +5278,9 @@ defmodule Module.Types.Descr do
{tag, elements} -> tuple_eliminate_negations(tag, elements, negs)
end
end)
# We want to avoid each_singleton? from failing,
# so we remove contiguous duplicates (cheaper than uniq)
|> Enum.dedup()
end

defp tuple_bdd_to_dnf_with_negations(bdd) do
Expand Down
10 changes: 10 additions & 0 deletions lib/elixir/test/elixir/module/types/descr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,16 @@ defmodule Module.Types.DescrTest do
refute singleton?(open_tuple([]))
refute singleton?(union(tuple([atom([:value])]), tuple([atom([:other_value])])))
refute singleton?(union(tuple([atom([:value])]), closed_map(other: atom([:value]))))

# Both BDD lines produce the same singleton tuple, so the tuple DNF must not duplicate it.
a = tuple([union(integer(), atom([:ok])), atom([:x])])
b = tuple([integer(), atom([:x, :y])])
c = tuple([integer(), union(atom([:x]), binary())])

t = union(difference(a, b), difference(a, c))
# Semantically t ~= {:ok, :x}, confirmed by equal?
assert equal?(t, tuple([atom([:ok]), atom([:x])]))
assert singleton?(t)
end
end

Expand Down
Loading