Skip to content

Commit

Permalink
Emit warning if True/False/Nil are used also outside of alias
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 17, 2023
1 parent da3e093 commit ddb2434
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/elixir/src/elixir_expand.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ expand({alias, Meta, [Ref, Opts]}, S, E) ->
assert_no_match_or_guard_scope(Meta, "alias", S, E),
{ERef, SR, ER} = expand_without_aliases_report(Ref, S, E),
{EOpts, ST, ET} = expand_opts(Meta, alias, [as, warn], no_alias_opts(Opts), SR, ER),
case lists:member(ERef, ['Elixir.True', 'Elixir.False', 'Elixir.Nil']) of
true -> elixir_errors:file_warn(Meta, E, ?MODULE, {commonly_mistaken_alias, Ref});
false -> ok
end,

if
is_atom(ERef) ->
{ERef, ST, expand_alias(Meta, true, ERef, EOpts, ET)};
Expand Down Expand Up @@ -1036,6 +1033,12 @@ expand_without_aliases_report(Other, S, E) ->
expand_aliases({'__aliases__', Meta, _} = Alias, S, E, Report) ->
case elixir_aliases:expand_or_concat(Alias, E) of
Receiver when is_atom(Receiver) ->
if
Receiver =:= 'Elixir.True'; Receiver =:= 'Elixir.False'; Receiver =:= 'Elixir.Nil' ->
elixir_errors:file_warn(Meta, E, ?MODULE, {commonly_mistaken_alias, Receiver});
true ->
ok
end,
Report andalso elixir_env:trace({alias_reference, Meta, Receiver}, E),
{Receiver, S, E};

Expand Down

0 comments on commit ddb2434

Please sign in to comment.