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
2 changes: 0 additions & 2 deletions lib/elixir/lib/module/types/descr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ defmodule Module.Types.Descr do
"""
def intersection(:term, other), do: remove_optional(other)
def intersection(other, :term), do: remove_optional(other)
def intersection(%{dynamic: :term}, other), do: dynamic(remove_optional(other))
def intersection(other, %{dynamic: :term}), do: dynamic(remove_optional(other))

def intersection(left, right) do
is_gradual_left = gradual?(left)
Expand Down
5 changes: 5 additions & 0 deletions lib/elixir/test/elixir/module/types/descr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,11 @@ defmodule Module.Types.DescrTest do
assert truthiness(dynamic(type)) == :always_false
end

assert equal?(
intersection(union(atom(), dynamic()), union(atom(), dynamic())),
union(atom(), dynamic())
)

for type <-
[negation(atom()), atom([true]), negation(atom([false, nil])), atom([:ok]), integer()] do
assert truthiness(type) == :always_true
Expand Down
14 changes: 14 additions & 0 deletions lib/elixir/test/elixir/module/types/expr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,20 @@ defmodule Module.Types.ExprTest do
assert typecheck!([x = 123, y = 456.0], x == y) == boolean()
end

test "preserves static components across gradual self-intersections" do
assert typecheck!(
[x],
(
# y :: :foo or dynamic()
y = if :rand.uniform() > 0.5, do: :foo, else: x
# y's type intersected with itself
y = y

y
)
) == union(atom([:foo]), dynamic())
end

test "in dynamic mode" do
assert typedyn!([x = 123, y = 456.0], x < y) == dynamic(boolean())
assert typedyn!([x = 123, y = 456.0], x == y) == dynamic(boolean())
Expand Down
Loading