Skip to content

Commit 2567938

Browse files
committed
Bring conditional violation reports back
1 parent baa7b5e commit 2567938

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ defmodule Kernel do
19741974

19751975
defp build_boolean_check(operator, check, true_clause, false_clause) do
19761976
annotate_case(
1977-
[optimize_boolean: true],
1977+
[optimize_boolean: true, type_check: :expr],
19781978
quote do
19791979
case unquote(check) do
19801980
false -> unquote(false_clause)
@@ -2008,7 +2008,7 @@ defmodule Kernel do
20082008
assert_no_match_or_guard_scope(__CALLER__.context, "!")
20092009

20102010
annotate_case(
2011-
[optimize_boolean: true],
2011+
[optimize_boolean: true, type_check: :expr],
20122012
quote do
20132013
case unquote(value) do
20142014
x when :"Elixir.Kernel".in(x, [false, nil]) -> false
@@ -2022,7 +2022,7 @@ defmodule Kernel do
20222022
assert_no_match_or_guard_scope(__CALLER__.context, "!")
20232023

20242024
annotate_case(
2025-
[optimize_boolean: true],
2025+
[optimize_boolean: true, type_check: :expr],
20262026
quote do
20272027
case unquote(value) do
20282028
x when :"Elixir.Kernel".in(x, [false, nil]) -> true
@@ -3912,7 +3912,7 @@ defmodule Kernel do
39123912

39133913
defp build_if(condition, do: do_clause, else: else_clause) do
39143914
annotate_case(
3915-
[optimize_boolean: true],
3915+
[optimize_boolean: true, type_check: :expr],
39163916
quote do
39173917
case unquote(condition) do
39183918
x when :"Elixir.Kernel".in(x, [false, nil]) -> unquote(else_clause)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,14 @@ defmodule Module.Types.ExprTest do
11391139
test "and does not report on literals" do
11401140
assert typecheck!(false and true) == boolean()
11411141
end
1142+
1143+
test "and reports violations" do
1144+
assert typeerror!([x = 123], x and true) =~ """
1145+
the following conditional expression will always evaluate to integer():
1146+
1147+
x
1148+
"""
1149+
end
11421150
end
11431151

11441152
describe "receive" do

0 commit comments

Comments
 (0)