Skip to content

Commit c295ee5

Browse files
committed
Allow expansion of local macros via Macro.expand/2
1 parent 54c25a5 commit c295ee5

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/elixir/lib/macro.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ defmodule Macro do
867867
end
868868

869869
expand = :elixir_dispatch.expand_import(meta, {atom, length(args)}, args,
870-
env, extra)
870+
env, extra, true)
871871

872872
case expand do
873873
{:ok, receiver, quoted} ->

lib/elixir/src/elixir_dispatch.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-module(elixir_dispatch).
55
-export([dispatch_import/5, dispatch_require/6,
66
require_function/5, import_function/4,
7-
expand_import/5, expand_require/5,
7+
expand_import/6, expand_require/5,
88
default_functions/0, default_macros/0, default_requires/0,
99
find_import/4, format_error/1]).
1010
-include("elixir.hrl").
@@ -88,7 +88,7 @@ remote_function(Meta, Receiver, Name, Arity, E) ->
8888

8989
dispatch_import(Meta, Name, Args, E, Callback) ->
9090
Arity = length(Args),
91-
case expand_import(Meta, {Name, Arity}, Args, E, []) of
91+
case expand_import(Meta, {Name, Arity}, Args, E, [], false) of
9292
{ok, Receiver, Quoted} ->
9393
expand_quoted(Meta, Receiver, Name, Arity, Quoted, E);
9494
{ok, Receiver, NewName, NewArgs} ->
@@ -115,12 +115,12 @@ dispatch_require(_Meta, Receiver, Name, Args, _E, Callback) ->
115115

116116
%% Macros expansion
117117

118-
expand_import(Meta, {Name, Arity} = Tuple, Args, E, Extra) ->
119-
Module = ?m(E, module),
120-
Dispatch = find_dispatch(Meta, Tuple, Extra, E),
121-
Function = ?m(E, function),
122-
Local = (Function /= nil) andalso (Function /= Tuple) andalso
123-
elixir_locals:macro_for(Module, Name, Arity),
118+
expand_import(Meta, {Name, Arity} = Tuple, Args, E, Extra, External) ->
119+
Module = ?m(E, module),
120+
Dispatch = find_dispatch(Meta, Tuple, Extra, E),
121+
Function = ?m(E, function),
122+
AllowLocals = External orelse ((Function /= nil) andalso (Function /= Tuple)),
123+
Local = AllowLocals andalso elixir_locals:macro_for(Module, Name, Arity),
124124

125125
case Dispatch of
126126
%% In case it is an import, we dispatch the import.

0 commit comments

Comments
 (0)