Make sure struct expansion results in a remote dispatch (#4807)

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
This commit is contained in:
Eric Entin
2016-06-12 23:52:09 +02:00
committed by José Valim
parent 2b5e69aa05
commit 92cf02321b
2 changed files with 14 additions and 9 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ expand_struct(Meta, Left, Right, #{context := Context} = E) ->
true when is_atom(ELeft) ->
%% We always record structs when they are expanded
%% as they expect the reference at compile time.
elixir_lexical:record_remote(ELeft, nil, ?m(E, lexical_tracker));
elixir_lexical:record_remote(ELeft, '__struct__', 1, nil, ?line(Meta), ?m(E, lexical_tracker));
true ->
ok;
false when Context == match ->
@@ -161,6 +161,7 @@ defmodule Kernel.LexicalTrackerTest do
&R.func/0
&Remote.func/0
&Integer.is_even/1
%Macro.Env{}
end
&extract/2
@@ -171,6 +172,8 @@ defmodule Kernel.LexicalTrackerTest do
&is_record/1; def b(a), do: is_record(a)
%Macro.Env{}
Kernel.LexicalTracker.remote_dispatches(__ENV__.module)
end |> elem(3)
""")
@@ -181,14 +184,16 @@ defmodule Kernel.LexicalTrackerTest do
assert {9, Integer, :is_even, 1} in compile_remote_calls
assert {15, Record, :is_record, 1} in compile_remote_calls
assert {18, Integer, :is_even, 1} in compile_remote_calls
assert {21, Record, :extract, 2} in compile_remote_calls
assert {22, Record, :is_record, 1} in compile_remote_calls
assert {23, Remote, :func, 0} in compile_remote_calls
assert {19, Macro.Env, :__struct__, 1} in compile_remote_calls
assert {22, Record, :extract, 2} in compile_remote_calls
assert {23, Record, :is_record, 1} in compile_remote_calls
assert {24, Remote, :func, 0} in compile_remote_calls
assert {25, Integer, :is_even, 1} in compile_remote_calls
assert {27, Kernel, :def, 2} in compile_remote_calls
assert {27, Record, :is_record, 1} in compile_remote_calls
assert {29, Kernel.LexicalTracker, :remote_dispatches, 1} in compile_remote_calls
assert {25, Remote, :func, 0} in compile_remote_calls
assert {26, Integer, :is_even, 1} in compile_remote_calls
assert {28, Kernel, :def, 2} in compile_remote_calls
assert {28, Record, :is_record, 1} in compile_remote_calls
assert {30, Macro.Env, :__struct__, 1} in compile_remote_calls
assert {32, Kernel.LexicalTracker, :remote_dispatches, 1} in compile_remote_calls
runtime_remote_calls = unroll_dispatches(runtime_remote_calls)
assert {7, Record, :extract, 2} in runtime_remote_calls
@@ -200,7 +205,7 @@ defmodule Kernel.LexicalTrackerTest do
assert {16, Remote, :func, 0} in runtime_remote_calls
assert {17, Remote, :func, 0} in runtime_remote_calls
assert {18, :erlang, :==, 2} in runtime_remote_calls
assert {27, :erlang, :is_tuple, 1} in runtime_remote_calls
assert {28, :erlang, :is_tuple, 1} in runtime_remote_calls
end
defp unroll_dispatches(dispatches) do