Skip to content

Commit 425c68e

Browse files
committed
Simplify conditional handling
1 parent 989e35f commit 425c68e

File tree

4 files changed

+8
-32
lines changed

4 files changed

+8
-32
lines changed

lib/elixir/lib/module/types/helpers.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ defmodule Module.Types.Helpers do
223223
if Keyword.get(meta, :generated, false) do
224224
context
225225
else
226-
effective_warn(module, warning, meta, stack, context)
226+
effectively_warn(module, warning, meta, stack, context)
227227
end
228228
end
229229

230-
defp effective_warn(module, warning, meta, stack, context) do
230+
defp effectively_warn(module, warning, meta, stack, context) do
231231
{fun, arity} = stack.function
232232
location = {stack.file, meta, {stack.module, fun, arity}}
233233
%{context | warnings: [{module, warning, location} | context.warnings]}
@@ -247,7 +247,7 @@ defmodule Module.Types.Helpers do
247247
if Keyword.get(meta, :generated, false) do
248248
context
249249
else
250-
effective_warn(module, warning, meta, stack, %{context | failed: true})
250+
effectively_warn(module, warning, meta, stack, %{context | failed: true})
251251
end
252252
end
253253
end

lib/elixir/src/elixir_erl_compiler.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ format_warnings(Opts, Warnings) ->
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;
121121

122-
%% We skip all of no_clause, clause_type, guard, shadow.
122+
%% We skip all of no_match related to no_clause, clause_type, guard, shadow.
123123
%% Those have too little information and they overlap with the type system.
124+
%% We keep the remaining ones because the Erlang compiler performs analyses
125+
%% on literals (including numbers), which the type system does not do.
124126
handle_file_warning(_, _File, {_Line, sys_core_fold, {nomatch, Reason}}) when is_atom(Reason) -> ok;
125127

126128
%% Ignore all linting errors (only come up on parse transforms)

lib/elixir/src/elixir_expand.erl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -732,17 +732,7 @@ expand_case(Meta, Expr, Opts, S, E) ->
732732
end,
733733

734734
{EOpts, SO, EO} = elixir_clauses:'case'(Meta, ROpts, SE, EE),
735-
736-
case prune_case_clauses(EExpr, EOpts) of
737-
{ok, Pruned} -> {Pruned, SO, EO};
738-
error -> {{'case', Meta, [EExpr, EOpts]}, SO, EO}
739-
end.
740-
741-
prune_case_clauses(false, [{do, [{'->', _, [[false], Body]}, {'->', _, [[true], _]}]}]) -> {ok, Body};
742-
prune_case_clauses(false, [{do, [{'->', _, [[true], _]}, {'->', _, [[false], Body]}]}]) -> {ok, Body};
743-
prune_case_clauses(true, [{do, [{'->', _, [[false], _]}, {'->', _, [[true], Body]}]}]) -> {ok, Body};
744-
prune_case_clauses(true, [{do, [{'->', _, [[true], Body]}, {'->', _, [[false], _]}]}]) -> {ok, Body};
745-
prune_case_clauses(_, _) -> error.
735+
{{'case', Meta, [EExpr, EOpts]}, SO, EO}.
746736

747737
rewrite_case_clauses([{do, [
748738
{'->', FalseMeta, [

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,22 +1049,6 @@ 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
10681052
end
10691053

10701054
describe "conditionals" do
@@ -1073,7 +1057,7 @@ defmodule Module.Types.ExprTest do
10731057
if true do
10741058
:ok
10751059
end
1076-
) == atom([:ok])
1060+
) == atom([:ok, nil])
10771061
end
10781062
end
10791063

0 commit comments

Comments
 (0)