Skip to content
Closed
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: 2 additions & 0 deletions lib/elixir/lib/module/types/apply.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ defmodule Module.Types.Apply do
{:erlang, :apply, [{[fun(), list(term())], dynamic()}]},
{:erlang, :apply, [{[atom(), atom(), list(term())], dynamic()}]},
{:erlang, :and, and_signature},
{:erlang, :andalso, and_signature},
{:erlang, :atom_to_binary, [{[atom()], binary()}]},
{:erlang, :atom_to_list, [{[atom()], list(integer())}]},
{:erlang, :band, [{[integer(), integer()], integer()}]},
Expand Down Expand Up @@ -201,6 +202,7 @@ defmodule Module.Types.Apply do
{:erlang, :node, [{[pid() |> union(reference()) |> union(port())], atom()}]},
{:erlang, :not, not_signature},
{:erlang, :or, or_signature},
{:erlang, :orelse, or_signature},
{:erlang, :raise, [{[atom([:error, :exit, :throw]), term(), raise_stacktrace], none()}]},
{:erlang, :rem, [{[integer(), integer()], integer()}]},
{:erlang, :round, [{[union(integer(), float())], integer()}]},
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/module/types/pattern.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ defmodule Module.Types.Pattern do
{union(type, @dynamic_fail), context}
end

defp of_remote(fun, _args, call, expected, stack, context)
defp of_remote(fun, _args, call, expected, stack, %{pattern_info: %{}} = context)
when fun in [:and, :or, :andalso, :orelse] do
{both_domain, abort_domain, always_rhs?} =
case fun do
Expand Down
23 changes: 23 additions & 0 deletions lib/elixir/test/elixir/module/types/pattern_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,29 @@ defmodule Module.Types.PatternTest do
assert typecheck!([x = {}], not (x == :foo), x) == dynamic(tuple([]))
assert typecheck!([x = {}], x != :foo, x) == dynamic(tuple([]))
end

test "with orelse/andalso nested in comparison" do
# Verify that orelse and andalso guard evaluation works correctly
assert typecheck!([a, b, c], a != (b or c), :ok) == atom([:ok])
assert typecheck!([a, b, c], a == (b or c), :ok) == atom([:ok])
assert typecheck!([a, b, c], a !== (b or c), :ok) == atom([:ok])
assert typecheck!([a, b, c], a === (b or c), :ok) == atom([:ok])
assert typecheck!([a, b, c], a == hd(b or c), :ok) == atom([:ok])
assert typecheck!([a, b, c], a != (b and c), :ok) == atom([:ok])
assert typecheck!([a, b, c], a == (b and c), :ok) == atom([:ok])

# Verify type precision is not lost through orelse/andalso re-evaluation
assert typecheck!([a, b], a and b, a) == dynamic(atom([true]))
assert typecheck!([a, b, c], a === (b or c), a) == dynamic(boolean())
assert typecheck!([a, b, c], a === (b and c), a) == dynamic(boolean())
assert typecheck!([a], a, a) == dynamic(atom([true]))
assert typecheck!([a, b], a or b, a) == dynamic(boolean())
assert typecheck!([a, b, c], b and a === (b or c), a) == dynamic(atom([true]))
assert typecheck!([a, b, c], c and a === (b or c), a) == dynamic(atom([true]))
assert typecheck!([a, b, c], b and a === (b and c), a) == dynamic(boolean())
assert typecheck!([a, b, c], b and a === (not b and c), a) == dynamic(atom([false]))
assert typecheck!([a, b, c], not b and a === (b and c), a) == dynamic(atom([false]))
end
end

describe "size comparison in guards" do
Expand Down
Loading