From a4894eabd2117dbb8e98365e9f87acf8c7a1ae33 Mon Sep 17 00:00:00 2001
From: Patrik Nyblom <pan@erlang.org>
Date: Fri, 21 May 2010 12:02:04 +0200
Subject: Teach compiler to override autoimport with import

---
 lib/compiler/src/sys_pre_expand.erl | 16 ++++++++--------
 lib/stdlib/src/erl_lint.erl         | 31 +++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 12 deletions(-)

(limited to 'lib')

diff --git a/lib/compiler/src/sys_pre_expand.erl b/lib/compiler/src/sys_pre_expand.erl
index 590b8b07d8..480954adac 100644
--- a/lib/compiler/src/sys_pre_expand.erl
+++ b/lib/compiler/src/sys_pre_expand.erl
@@ -407,14 +407,14 @@ expr({call,Line,{atom,La,N}=Atom,As0}, St0) ->
 	true ->
 	    {{call,Line,Atom,As},St1};
 	_ ->
-	    case erl_internal:bif(N, Ar) of
-		true ->
-		    {{call,Line,{remote,La,{atom,La,erlang},Atom},As},St1};
-		false ->
-		    case imported(N, Ar, St1) of
-			{yes,Mod} ->
-			    {{call,Line,{remote,La,{atom,La,Mod},Atom},As},St1};
-			no -> % Let the error come later, this call is to an undefined function...
+	    case imported(N, Ar, St1) of
+		{yes,Mod} ->
+		    {{call,Line,{remote,La,{atom,La,Mod},Atom},As},St1};
+		no ->
+		    case erl_internal:bif(N, Ar) of
+			true ->
+			    {{call,Line,{remote,La,{atom,La,erlang},Atom},As},St1};
+			false -> %% This should have been handled by erl_lint
 			    {{call,Line,Atom,As},St1}
 		    end
 	    end
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index 1e5464231d..89e31ba7e0 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -189,6 +189,8 @@ format_error({unused_function,{F,A}}) ->
     io_lib:format("function ~w/~w is unused", [F,A]);
 format_error({redefine_bif,{F,A}}) ->
     io_lib:format("redefining autoimported BIF ~w/~w", [F,A]);
+format_error({redefine_bif_import,{F,A}}) ->
+    io_lib:format("import directive redefines autoimported BIF ~w/~w", [F,A]);
 
 format_error({deprecated, MFA, ReplacementMFA, Rel}) ->
     io_lib:format("~s is deprecated and will be removed in ~s; use ~s",
@@ -1091,11 +1093,32 @@ import(Line, {Mod,Fs}, St) ->
                     St#lint{imports=add_imports(list_to_atom(Mod1), Mfs,
                                                 St#lint.imports)};
                 Efs ->
-                    foldl(fun (Ef, St0) ->
-                                  add_error(Line, {redefine_import,Ef},
-                                            St0)
+		    {Err, St1} =
+			foldl(fun ({bif,{F,A},_}, {Err,St0}) ->
+				      Warn = is_warn_enabled(bif_clash, St0),
+				      {Err,if
+					       Warn ->
+						   add_warning
+						     (Line,
+					     {redefine_bif_import, {F,A}},
+						      St0);
+					       true ->
+					  St0
+					   end};
+				  (Ef, {_Err,St0}) ->
+				      {true,add_error(Line,
+						      {redefine_import,Ef},
+						      St0)}
                           end,
-                          St, Efs)
+                          {false,St}, Efs),
+		    if
+			not Err ->
+			    St1#lint{imports=
+				     add_imports(list_to_atom(Mod1), Mfs,
+						 St#lint.imports)};
+			true ->
+			    St1
+		    end
             end;
         false ->
             add_error(Line, {bad_module_name, Mod1}, St)
-- 
cgit v1.2.3