aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-01-17 15:27:26 +0100
committerBjörn Gustavsson <[email protected]>2012-01-17 18:00:21 +0100
commite3b658cbc9b5838ed2596cc30790c26bfa90953f (patch)
tree832eed48aa35e345cee7e17edbe7245a0eecdbc2 /lib/stdlib/src
parentf8815dc88bd86d6508d2a3dad031ea939fb2b443 (diff)
downloadotp-e3b658cbc9b5838ed2596cc30790c26bfa90953f.tar.gz
otp-e3b658cbc9b5838ed2596cc30790c26bfa90953f.tar.bz2
otp-e3b658cbc9b5838ed2596cc30790c26bfa90953f.zip
erl_lint: Consistently reject local calls from guards
If a guard test (such as is_list/1) has a local definition in a module (or is imported), erl_lint will reject a call to it from a guard if the call is not at the top-level: foo(L) when is_list(L) =:= true -> %% Will be rejected. ok. is_list(_) -> ok. But if the call is at the top-level, it will be accepted (and cause a crash in a later compiler pass): foo(L) when is_list(L) -> %% Will be accepted by erl_lint ok. is_list(_) -> ok. This inconsistency was an oversight introduced when it became possible to override BIFs with local definitions.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/erl_lint.erl13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index e5adb84932..2f29954dc9 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -1804,12 +1804,19 @@ guard_test(G, Vt, St0) ->
%% Specially handle record type test here.
guard_test2({call,Line,{atom,Lr,record},[E,A]}, Vt, St0) ->
gexpr({call,Line,{atom,Lr,is_record},[E,A]}, Vt, St0);
-guard_test2({call,_Line,{atom,_La,F},As}=G, Vt, St0) ->
+guard_test2({call,Line,{atom,_La,F},As}=G, Vt, St0) ->
{Asvt,St1} = gexpr_list(As, Vt, St0), %Always check this.
A = length(As),
case erl_internal:type_test(F, A) of
- true when F =/= is_record -> {Asvt,St1};
- _ -> gexpr(G, Vt, St0)
+ true when F =/= is_record ->
+ case no_guard_bif_clash(St1, {F,A}) of
+ false ->
+ {Asvt,add_error(Line, {illegal_guard_local_call,{F,A}}, St1)};
+ true ->
+ {Asvt,St1}
+ end;
+ _ ->
+ gexpr(G, Vt, St0)
end;
guard_test2(G, Vt, St) ->
%% Everything else is a guard expression.