Skip to content

Commit 014b12a

Browse files
committed
More assertions
1 parent ca2eb39 commit 014b12a

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

lib/elixir/src/elixir_erl_compiler.erl

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ format_warnings(Opts, Warnings) ->
118118
%% Those we implement ourselves
119119
handle_file_warning(_, _File, {_Line, v3_core, {map_key_repeated, _}}) -> ok;
120120
handle_file_warning(_, _File, {_Line, sys_core_fold, {ignored, useless_building}}) -> ok;
121+
handle_file_warning(_, _File, {_Line, sys_core_fold, {nomatch, _}}) -> ok;
121122

122123
%% Ignore all linting errors (only come up on parse transforms)
123124
handle_file_warning(_, _File, {_Line, erl_lint, _}) -> ok;
@@ -150,18 +151,6 @@ custom_format(sys_core_fold, {ignored, {no_effect, {erlang, F, A}}}) ->
150151
end,
151152
io_lib:format(Fmt, Args);
152153

153-
%% Rewrite nomatch to be more generic, it can happen inside if, unless, and the like
154-
custom_format(sys_core_fold, {nomatch, X}) when X == guard; X == no_clause ->
155-
"this check/guard will always yield the same result";
156-
157-
custom_format(sys_core_fold, {nomatch, {shadow, Line, {ErlName, ErlArity}}}) ->
158-
{Name, Arity} = elixir_utils:erl_fa_to_elixir_fa(ErlName, ErlArity),
159-
160-
io_lib:format(
161-
"this clause for ~ts/~B cannot match because a previous clause at line ~B always matches",
162-
[Name, Arity, Line]
163-
);
164-
165154
custom_format([], Desc) ->
166155
io_lib:format("~p", [Desc]);
167156

lib/elixir/src/elixir_expand.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,9 @@ expand_case(Meta, Expr, Opts, S, E) ->
739739
end.
740740

741741
prune_case_clauses(false, [{do, [{'->', _, [[false], Body]}, {'->', _, [[true], _]}]}]) -> {ok, Body};
742+
prune_case_clauses(false, [{do, [{'->', _, [[true], _]}, {'->', _, [[false], Body]}]}]) -> {ok, Body};
742743
prune_case_clauses(true, [{do, [{'->', _, [[false], _]}, {'->', _, [[true], Body]}]}]) -> {ok, Body};
744+
prune_case_clauses(true, [{do, [{'->', _, [[true], Body]}, {'->', _, [[false], _]}]}]) -> {ok, Body};
743745
prune_case_clauses(_, _) -> error.
744746

745747
rewrite_case_clauses([{do, [

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,22 @@ defmodule Module.Types.ExprTest do
10491049

10501050
assert type == atom([:ok, :error])
10511051
end
1052+
1053+
test "does not report on literal booleans" do
1054+
assert typecheck!(
1055+
case true do
1056+
true -> :ok
1057+
false -> :error
1058+
end
1059+
) == atom([:ok])
1060+
1061+
assert typecheck!(
1062+
case false do
1063+
true -> :ok
1064+
false -> :error
1065+
end
1066+
) == atom([:error])
1067+
end
10521068
end
10531069

10541070
describe "conditionals" do

0 commit comments

Comments
 (0)