Skip to content

Commit 96ba934

Browse files
author
José Valim
committed
Continue raising on unbound __CALLER__
1 parent ea8eff3 commit 96ba934

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

lib/elixir/src/elixir.hrl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
-define(var_context, ?MODULE).
66

77
-record(elixir_erl, {
8-
def=nil, %% the definition kind (def, defp, etc)
98
context=nil, %% can be match, guards or nil
109
extra=nil, %% extra information about the context, like pin_guard and map_key
1110
caller=false, %% when true, it means caller was invoked

lib/elixir/src/elixir_erl.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-module(elixir_erl).
33
-export([elixir_to_erl/1, definition_to_anonymous/5, compile/1,
44
get_ann/1, remote/4, add_beam_chunks/2, debug_info/4,
5-
definition_scope/3]).
5+
definition_scope/2]).
66
-include("elixir.hrl").
77

88
%% TODO: Remove extra chunk functionality when OTP 20+.
@@ -137,14 +137,14 @@ elixir_to_erl_cons2([], Acc) ->
137137

138138
%% Returns a definition scope for translation.
139139

140-
definition_scope(Meta, Kind, File) ->
140+
definition_scope(Meta, File) ->
141141
%% TODO: We only need to do this dance because some
142142
%% warnings are raised in elixir_erl_pass. Once we remove
143143
%% all warnings from the Erlang pass, we can remove the
144144
%% file field from #elixir_erl and clean up the code.
145145
case lists:keyfind(location, 1, Meta) of
146-
{location, {F, _}} -> #elixir_erl{def=Kind,file=F};
147-
false -> #elixir_erl{def=Kind,file=File}
146+
{location, {F, _}} -> #elixir_erl{file=F};
147+
false -> #elixir_erl{file=File}
148148
end.
149149

150150
%% Compilation hook.
@@ -234,7 +234,7 @@ translate_definition(Kind, Meta, File, {Name, Arity}, Clauses) ->
234234
end.
235235

236236
translate_clause(Kind, {Meta, Args, Guards, Body}, File) ->
237-
S = definition_scope(Meta, Kind, File),
237+
S = definition_scope(Meta, File),
238238

239239
{TClause, TS} = elixir_erl_clauses:clause(Meta,
240240
fun elixir_erl_pass:translate_args/2, Args, Body, Guards, S),

lib/elixir/src/elixir_erl_pass.erl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,8 @@ translate({'__block__', Meta, Args}, S) when is_list(Args) ->
3838

3939
%% Compilation environment macros
4040

41-
translate({'__CALLER__', Meta, Atom}, #elixir_erl{def=Kind}=S) when is_atom(Atom) ->
42-
if
43-
Kind == defmacro; Kind == defmacrop ->
44-
{{var, ?ann(Meta), '__CALLER__'}, S#elixir_erl{caller=true}};
45-
true ->
46-
{{atom, ?ann(Meta), nil}, S}
47-
end;
41+
translate({'__CALLER__', Meta, Atom}, S) when is_atom(Atom) ->
42+
{{var, ?ann(Meta), '__CALLER__'}, S#elixir_erl{caller=true}};
4843

4944
translate({'super', Meta, [{Kind, Name} | Args]}, S) ->
5045
%% In the expanded AST, super is used to invoke a function

lib/elixir/test/elixir/kernel/errors_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ defmodule Kernel.ErrorsTest do
1515
'[foo: \u200B]\noops'
1616
end
1717

18+
test "invalid __CALLER__" do
19+
assert_compile_fail CompileError,
20+
"nofile:1: variable '__CALLER__' is unbound",
21+
'defmodule Sample do def hello do __CALLER__ end end'
22+
end
23+
1824
test "invalid quoted token" do
1925
assert_compile_fail SyntaxError,
2026
"nofile:1: syntax error before: \"world\"",

lib/elixir/test/elixir/kernel/expansion_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ defmodule Kernel.ExpansionTest do
169169
assert expand(quote do: __DIR__) == __DIR__
170170
end
171171

172-
test "__CALLER__" do
173-
assert __CALLER__ == nil
174-
assert expand(quote do: __CALLER__) == quote do: __CALLER__
175-
end
176-
177172
test "__ENV__" do
178173
env = %{__ENV__ | line: 0}
179174
assert expand_env(quote(do: __ENV__), env) ==

0 commit comments

Comments
 (0)