Skip to content

Commit aba0d5b

Browse files
author
José Valim
committed
Simplify current module macro handling
1 parent d334c1d commit aba0d5b

File tree

4 files changed

+13
-62
lines changed

4 files changed

+13
-62
lines changed

lib/elixir/src/elixir_dispatch.erl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,12 @@ expand_require(Meta, ?builtin, { Name, Arity } = Tuple, Args, Module, S) ->
190190
expand_require(Meta, Receiver, { Name, Arity } = Tuple, Args, Module, S) ->
191191
Function = S#elixir_scope.function,
192192

193-
Fun = (Module == Receiver) andalso (Function /= nil) andalso
194-
(Function /= Tuple) andalso elixir_def_local:macro_for(Tuple, false, S),
195-
196-
case Fun of
197-
false ->
198-
case is_element(Tuple, get_optional_macros(Receiver)) of
199-
true ->
200-
elixir_lexical:record_remote(Receiver, S#elixir_scope.lexical_tracker),
201-
elixir_tracker:record_remote(Tuple, Receiver, Module, Function),
202-
{ ok, Receiver, expand_macro_named(Meta, Receiver, Name, Arity, Args, Module, S) };
203-
false -> { error, noexpansion }
204-
end;
205-
_ ->
206-
elixir_tracker:record_local(Tuple, Module, Function),
207-
{ ok, Receiver, expand_macro_fun(Meta, Fun(), Receiver, Name, Args, Module, S) }
193+
case is_element(Tuple, get_optional_macros(Receiver)) of
194+
true ->
195+
elixir_lexical:record_remote(Receiver, S#elixir_scope.lexical_tracker),
196+
elixir_tracker:record_remote(Tuple, Receiver, Module, Function),
197+
{ ok, Receiver, expand_macro_named(Meta, Receiver, Name, Arity, Args, Module, S) };
198+
false -> { error, noexpansion }
208199
end.
209200

210201
%% Expansion helpers

lib/elixir/src/elixir_translator.erl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ forms(String, StartLine, File, Opts) ->
3434
translate(Forms, S) ->
3535
lists:mapfoldl(fun translate_each/2, S, Forms).
3636

37-
%% Those macros are "low-level". They are the basic mechanism
38-
%% that makes the language work and cannot be partially applied
39-
%% nor overwritten.
40-
4137
%% Assignment operator
4238

4339
translate_each({ '=', Meta, [Left, Right] }, S) ->
@@ -294,7 +290,7 @@ translate_each({ fn, Meta, [{ '->', _, Pairs }] }, S) ->
294290
translate_each({ Kind, Meta, Args }, S) when is_list(Args), (Kind == lc) orelse (Kind == bc) ->
295291
translate_comprehension(Meta, Kind, Args, S);
296292

297-
%% Super (exceptionally supports partial application)
293+
%% Super
298294

299295
translate_each({ super, Meta, Args }, S) when is_list(Args) ->
300296
assert_no_match_or_guard_scope(Meta, super, S),

lib/elixir/test/elixir/kernel/def_clauses_test.exs

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/elixir/test/elixir/kernel/macros_test.exs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Code.require_file "../test_helper.exs", __DIR__
22

33
defmodule Kernel.MacrosTest.Nested do
44
defmacro value, do: 1
5+
6+
defmacro do_identity!(do: x) do
7+
x
8+
end
59
end
610

711
defmodule Kernel.MacrosTest do
@@ -21,10 +25,6 @@ defmodule Kernel.MacrosTest do
2125
quote do: 1 + unquote(value)
2226
end
2327

24-
defmacro do_identity!(do: x) do
25-
x
26-
end
27-
2828
test :require do
2929
assert Kernel.MacrosTest.Nested.value == 1
3030
end
@@ -42,10 +42,6 @@ defmodule Kernel.MacrosTest do
4242
assert result
4343
end
4444

45-
test :locals_macros do
46-
assert __MODULE__.my_macro == 2
47-
end
48-
4945
test :local_but_private_macro do
5046
assert my_private_macro == 4
5147
end
@@ -60,7 +56,8 @@ defmodule Kernel.MacrosTest do
6056
end
6157

6258
test :bang_do_block do
59+
import Kernel.MacrosTest.Nested
6360
assert (do_identity! do 1 end) == 1
64-
assert (__MODULE__.do_identity! do 1 end) == 1
61+
assert (Kernel.MacrosTest.Nested.do_identity! do 1 end) == 1
6562
end
6663
end

0 commit comments

Comments
 (0)