8
8
-module (elixir_dispatch ).
9
9
-export ([dispatch_import /6 , dispatch_require /7 ,
10
10
require_function /5 , import_function /4 ,
11
- expand_import /8 , expand_require /6 , check_deprecated /6 ,
11
+ expand_import /7 , expand_require /6 , check_deprecated /6 ,
12
12
default_functions /0 , default_macros /0 , default_requires /0 ,
13
13
find_import /4 , find_imports /3 , format_error /1 ]).
14
14
-include (" elixir.hrl" ).
@@ -115,8 +115,7 @@ dispatch_import(Meta, Name, Args, S, E, Callback) ->
115
115
_ -> false
116
116
end ,
117
117
118
- DefaultLocalForCallback = fun (M , N , A , K , Env ) -> elixir_def :local_for (M , N , A , K , Env ) end ,
119
- case expand_import (Meta , Name , Arity , E , [], AllowLocals , true , DefaultLocalForCallback ) of
118
+ case expand_import (Meta , Name , Arity , E , [], AllowLocals , true ) of
120
119
{macro , Receiver , Expander } ->
121
120
check_deprecated (macro , Meta , Receiver , Name , Arity , E ),
122
121
Caller = {? line (Meta ), S , E },
@@ -160,7 +159,7 @@ dispatch_require(_Meta, Receiver, Name, _Args, _S, _E, Callback) ->
160
159
161
160
% % Macros expansion
162
161
163
- expand_import (Meta , Name , Arity , E , Extra , AllowLocals , Trace , LocalForCallback ) ->
162
+ expand_import (Meta , Name , Arity , E , Extra , AllowLocals , Trace ) ->
164
163
Tuple = {Name , Arity },
165
164
Module = ? key (E , module ),
166
165
Dispatch = find_import_by_name_arity (Meta , Tuple , Extra , E ),
@@ -173,7 +172,13 @@ expand_import(Meta, Name, Arity, E, Extra, AllowLocals, Trace, LocalForCallback)
173
172
do_expand_import (Dispatch , Meta , Name , Arity , Module , E , Trace );
174
173
175
174
_ ->
176
- Local = AllowLocals andalso LocalForCallback (Meta , Name , Arity , [defmacro , defmacrop ], E ),
175
+ Local = case AllowLocals of
176
+ false -> false ;
177
+ true -> elixir_def :local_for (Meta , Name , Arity , [defmacro , defmacrop ], E );
178
+ Fun when is_function (Fun , 5 ) ->
179
+ % % If we have a custom local resolver, use it.
180
+ Fun (Meta , Name , Arity , [defmacro , defmacrop ], E )
181
+ end ,
177
182
178
183
case Dispatch of
179
184
% % There is a local and an import. This is a conflict unless
@@ -250,22 +255,14 @@ expander_macro_named(Meta, Receiver, Name, Arity, E) ->
250
255
fun (Args , Caller ) -> expand_macro_fun (Meta , Fun , Receiver , Name , Args , Caller , E ) end .
251
256
252
257
expand_macro_fun (Meta , Fun , Receiver , Name , Args , Caller , E ) ->
253
- % % Check if Fun is actually a function, as it might be a fake value for local macros
254
- % % when using custom local_for_callback
255
- case is_function (Fun ) of
256
- true ->
257
- try
258
- apply (Fun , [Caller | Args ])
259
- catch
260
- Kind :Reason :Stacktrace ->
261
- Arity = length (Args ),
262
- MFA = {Receiver , elixir_utils :macro_name (Name ), Arity + 1 },
263
- Info = [{Receiver , Name , Arity , [{file , " expanding macro" }]}, caller (? line (Meta ), E )],
264
- erlang :raise (Kind , Reason , prune_stacktrace (Stacktrace , MFA , Info , {ok , Caller }))
265
- end ;
266
- false ->
267
- % % Return a fake value and omit expansion when Fun is not a function
268
- ok
258
+ try
259
+ apply (Fun , [Caller | Args ])
260
+ catch
261
+ Kind :Reason :Stacktrace ->
262
+ Arity = length (Args ),
263
+ MFA = {Receiver , elixir_utils :macro_name (Name ), Arity + 1 },
264
+ Info = [{Receiver , Name , Arity , [{file , " expanding macro" }]}, caller (? line (Meta ), E )],
265
+ erlang :raise (Kind , Reason , prune_stacktrace (Stacktrace , MFA , Info , {ok , Caller }))
269
266
end .
270
267
271
268
expand_quoted (Meta , Receiver , Name , Arity , Quoted , S , E ) ->
0 commit comments