From e3b658cbc9b5838ed2596cc30790c26bfa90953f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 17 Jan 2012 15:27:26 +0100 Subject: 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. --- lib/stdlib/test/erl_lint_SUITE.erl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/test/erl_lint_SUITE.erl') diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl index 9041adbe5c..e4c7fd5b02 100644 --- a/lib/stdlib/test/erl_lint_SUITE.erl +++ b/lib/stdlib/test/erl_lint_SUITE.erl @@ -2631,7 +2631,24 @@ bif_clash(Config) when is_list(Config) -> binary_part(A,B,C). ">>, [warn_unused_import], - {warnings,[{2,erl_lint,{redefine_bif_import,{binary_part,3}}}]}} + {warnings,[{2,erl_lint,{redefine_bif_import,{binary_part,3}}}]}}, + %% Don't accept call to a guard BIF if there is a local definition + %% or an import with the same name. + {clash21, + <<"-export([is_list/1]). + -import(x, [is_tuple/1]). + x(T) when is_tuple(T) -> ok; + x(T) when is_list(T) -> ok. + y(T) when is_tuple(T) =:= true -> ok; + y(T) when is_list(T) =:= true -> ok. + is_list(_) -> + ok. + ">>, + [{no_auto_import,[{is_tuple,1}]}], + {errors,[{3,erl_lint,{illegal_guard_local_call,{is_tuple,1}}}, + {4,erl_lint,{illegal_guard_local_call,{is_list,1}}}, + {5,erl_lint,{illegal_guard_local_call,{is_tuple,1}}}, + {6,erl_lint,{illegal_guard_local_call,{is_list,1}}}],[]}} ], ?line [] = run(Config, Ts), -- cgit v1.2.3