@@ -45,7 +45,7 @@ import_function(Meta, Name, Arity, S) ->
45
45
false ;
46
46
{ import , Receiver } ->
47
47
require_function (Meta , Receiver , Name , Arity , S );
48
- nomatch ->
48
+ false ->
49
49
case elixir_import :special_form (Name , Arity ) of
50
50
true -> false ;
51
51
false ->
@@ -123,6 +123,28 @@ expand_import(Meta, Tuple, Args, Module, Extra, S) ->
123
123
do_expand_import (Meta , Tuple , Args , Module , S , Result ).
124
124
125
125
do_expand_import (Meta , { Name , Arity } = Tuple , Args , Module , S , Result ) ->
126
+ Function = S # elixir_scope .function ,
127
+
128
+ Fun = (Function /= nil ) andalso (Function /= Tuple ) andalso
129
+ elixir_def_local :macro_for (Tuple , true , S ),
130
+
131
+ case Fun of
132
+ false ->
133
+ do_expand_import_no_local (Meta , Tuple , Args , Module , S , Result );
134
+ _ ->
135
+ case Result of
136
+ { Kind , Receiver } when Kind == import ; Receiver == Module ->
137
+ do_expand_import_no_local (Meta , Tuple , Args , Module , S , Result );
138
+ { _ , Receiver } ->
139
+ Error = { macro_conflict , { Receiver , Name , Arity } },
140
+ elixir_errors :form_error (Meta , S # elixir_scope .file , ? MODULE , Error );
141
+ false ->
142
+ elixir_tracker :record_local (Tuple , Module , S # elixir_scope .function ),
143
+ { ok , Module , expand_macro_fun (Meta , Fun (), Module , Name , Args , Module , S ) }
144
+ end
145
+ end .
146
+
147
+ do_expand_import_no_local (Meta , { Name , Arity } = Tuple , Args , Module , S , Result ) ->
126
148
case Result of
127
149
{ macro , ? builtin } ->
128
150
case is_element (Tuple , in_erlang_macros ()) of
@@ -137,13 +159,7 @@ do_expand_import(Meta, { Name, Arity } = Tuple, Args, Module, S, Result) ->
137
159
{ import , Receiver } ->
138
160
expand_require (Meta , Receiver , Tuple , Args , Module , S );
139
161
_ ->
140
- Fun = (S # elixir_scope .function /= Tuple ) andalso
141
- elixir_def_local :macro_for (Tuple , true , S ),
142
- case Fun of
143
- false -> { error , noexpansion };
144
- _ ->
145
- { ok , Module , expand_macro_fun (Meta , Fun , Module , Name , Args , Module , S ) }
146
- end
162
+ { error , noexpansion }
147
163
end .
148
164
149
165
expand_require (Meta , ? builtin , { Name , Arity } = Tuple , Args , Module , S ) ->
@@ -160,19 +176,22 @@ expand_require(Meta, ?builtin, { Name, Arity } = Tuple, Args, Module, S) ->
160
176
end ;
161
177
162
178
expand_require (Meta , Receiver , { Name , Arity } = Tuple , Args , Module , S ) ->
163
- Fun = (Module == Receiver ) andalso (S # elixir_scope .function /= Tuple ) andalso
164
- elixir_def_local :macro_for (Tuple , false , S ),
179
+ Function = S # elixir_scope .function ,
180
+
181
+ Fun = (Module == Receiver ) andalso (Function /= nil ) andalso
182
+ (Function /= Tuple ) andalso elixir_def_local :macro_for (Tuple , false , S ),
165
183
166
184
case Fun of
167
185
false ->
168
186
case is_element (Tuple , get_optional_macros (Receiver )) of
169
187
true ->
170
- elixir_tracker :record_remote (Tuple , Receiver , S # elixir_scope . module , S # elixir_scope . function ),
188
+ elixir_tracker :record_remote (Tuple , Receiver , Module , Function ),
171
189
{ ok , Receiver , expand_macro_named (Meta , Receiver , Name , Arity , Args , Module , S ) };
172
190
false -> { error , noexpansion }
173
191
end ;
174
192
_ ->
175
- { ok , Receiver , expand_macro_fun (Meta , Fun , Receiver , Name , Args , Module , S ) }
193
+ elixir_tracker :record_local (Tuple , Module , Function ),
194
+ { ok , Receiver , expand_macro_fun (Meta , Fun (), Receiver , Name , Args , Module , S ) }
176
195
end .
177
196
178
197
% % Expansion helpers
@@ -250,7 +269,7 @@ find_dispatch(Meta, Tuple, Extra, S) ->
250
269
case { FunMatch , MacMatch } of
251
270
{ [], [Receiver ] } -> { macro , Receiver };
252
271
{ [Receiver ], [] } -> { function , Receiver };
253
- { [], [] } -> nomatch ;
272
+ { [], [] } -> false ;
254
273
_ ->
255
274
{ Name , Arity } = Tuple ,
256
275
[First , Second |_ ] = FunMatch ++ MacMatch ,
@@ -322,6 +341,10 @@ format_error({ unrequired_module, { Receiver, Name, Arity, Required }}) ->
322
341
io_lib :format (" tried to invoke macro ~ts .~ts /~B but module was not required. Required: ~ts " ,
323
342
[elixir_errors :inspect (Receiver ), Name , Arity , String ]);
324
343
344
+ format_error ({ macro_conflict , { Receiver , Name , Arity } }) ->
345
+ io_lib :format (" call to local macro ~ts /~B conflicts with imported ~ts .~ts /~B " ,
346
+ [Name , Arity , elixir_errors :inspect (Receiver ), Name , Arity ]);
347
+
325
348
format_error ({ ambiguous_call , { Mod1 , Mod2 , Name , Arity }}) ->
326
349
io_lib :format (" function ~ts /~B imported from both ~ts and ~ts , call is ambiguous" ,
327
350
[Name , Arity , elixir_errors :inspect (Mod1 ), elixir_errors :inspect (Mod2 )]).
0 commit comments