Skip to content

Commit b9bd0e3

Browse files
committed
Bring conditional violation reports back
1 parent 6a3301f commit b9bd0e3

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
@@ -1972,7 +1972,7 @@ defmodule Kernel do
19721972

19731973
defp build_boolean_check(operator, check, true_clause, false_clause) do
19741974
annotate_case(
1975-
[optimize_boolean: true],
1975+
[optimize_boolean: true, type_check: :expr],
19761976
quote do
19771977
case unquote(check) do
19781978
false -> unquote(false_clause)
@@ -2006,7 +2006,7 @@ defmodule Kernel do
20062006
assert_no_match_or_guard_scope(__CALLER__.context, "!")
20072007

20082008
annotate_case(
2009-
[optimize_boolean: true],
2009+
[optimize_boolean: true, type_check: :expr],
20102010
quote do
20112011
case unquote(value) do
20122012
x when :"Elixir.Kernel".in(x, [false, nil]) -> false
@@ -2020,7 +2020,7 @@ defmodule Kernel do
20202020
assert_no_match_or_guard_scope(__CALLER__.context, "!")
20212021

20222022
annotate_case(
2023-
[optimize_boolean: true],
2023+
[optimize_boolean: true, type_check: :expr],
20242024
quote do
20252025
case unquote(value) do
20262026
x when :"Elixir.Kernel".in(x, [false, nil]) -> true
@@ -3910,7 +3910,7 @@ defmodule Kernel do
39103910

39113911
defp build_if(condition, do: do_clause, else: else_clause) do
39123912
annotate_case(
3913-
[optimize_boolean: true],
3913+
[optimize_boolean: true, type_check: :expr],
39143914
quote do
39153915
case unquote(condition) do
39163916
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)