Skip to content

Commit 7b0ae43

Browse files
committed
Address ambiguity on type violation in nested ||
1 parent 677afec commit 7b0ae43

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/elixir/lib/module/types/pattern.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,8 +1430,16 @@ defmodule Module.Types.Pattern do
14301430
#{to_quoted_string(type) |> indent(4)}
14311431
"""
14321432
else
1433+
additional =
1434+
with {:case, meta, [_, _]} <- expr,
1435+
{:case, :||} <- meta[:type_check] do
1436+
"(shown as ... below) "
1437+
else
1438+
_ -> ""
1439+
end
1440+
14331441
"""
1434-
the right-hand side of || will never be executed:
1442+
the right-hand side of || #{additional}will never be executed:
14351443
14361444
#{expr_to_string({:||, [], [expr, {:..., [], []}]}) |> indent(4)}
14371445

lib/elixir/test/elixir/module/types/expr_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,17 @@ defmodule Module.Types.ExprTest do
19631963
19641964
"""
19651965

1966+
assert typeerror!([x = 123], System.get_env("foo") || x || true) =~ """
1967+
the right-hand side of || (shown as ... below) will never be executed:
1968+
1969+
System.get_env("foo") || x || ...
1970+
1971+
because the left-hand side always evaluates to:
1972+
1973+
dynamic(binary() or integer())
1974+
1975+
"""
1976+
19661977
assert typeerror!([x = false], x || true) =~ """
19671978
the following conditional expression will never succeed:
19681979

0 commit comments

Comments
 (0)