Skip to content

Commit 92cf023

Browse files
ericentinJosé Valim
authored andcommitted
Make sure struct expansion results in a remote dispatch (#4807)
Signed-off-by: José Valim <[email protected]>
1 parent 2b5e69a commit 92cf023

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/elixir/src/elixir_map.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ expand_struct(Meta, Left, Right, #{context := Context} = E) ->
1919
true when is_atom(ELeft) ->
2020
%% We always record structs when they are expanded
2121
%% as they expect the reference at compile time.
22-
elixir_lexical:record_remote(ELeft, nil, ?m(E, lexical_tracker));
22+
elixir_lexical:record_remote(ELeft, '__struct__', 1, nil, ?line(Meta), ?m(E, lexical_tracker));
2323
true ->
2424
ok;
2525
false when Context == match ->

lib/elixir/test/elixir/kernel/lexical_tracker_test.exs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ defmodule Kernel.LexicalTrackerTest do
161161
&R.func/0
162162
&Remote.func/0
163163
&Integer.is_even/1
164+
%Macro.Env{}
164165
end
165166
166167
&extract/2
@@ -171,6 +172,8 @@ defmodule Kernel.LexicalTrackerTest do
171172
172173
&is_record/1; def b(a), do: is_record(a)
173174
175+
%Macro.Env{}
176+
174177
Kernel.LexicalTracker.remote_dispatches(__ENV__.module)
175178
end |> elem(3)
176179
""")
@@ -181,14 +184,16 @@ defmodule Kernel.LexicalTrackerTest do
181184
assert {9, Integer, :is_even, 1} in compile_remote_calls
182185
assert {15, Record, :is_record, 1} in compile_remote_calls
183186
assert {18, Integer, :is_even, 1} in compile_remote_calls
184-
assert {21, Record, :extract, 2} in compile_remote_calls
185-
assert {22, Record, :is_record, 1} in compile_remote_calls
186-
assert {23, Remote, :func, 0} in compile_remote_calls
187+
assert {19, Macro.Env, :__struct__, 1} in compile_remote_calls
188+
assert {22, Record, :extract, 2} in compile_remote_calls
189+
assert {23, Record, :is_record, 1} in compile_remote_calls
187190
assert {24, Remote, :func, 0} in compile_remote_calls
188-
assert {25, Integer, :is_even, 1} in compile_remote_calls
189-
assert {27, Kernel, :def, 2} in compile_remote_calls
190-
assert {27, Record, :is_record, 1} in compile_remote_calls
191-
assert {29, Kernel.LexicalTracker, :remote_dispatches, 1} in compile_remote_calls
191+
assert {25, Remote, :func, 0} in compile_remote_calls
192+
assert {26, Integer, :is_even, 1} in compile_remote_calls
193+
assert {28, Kernel, :def, 2} in compile_remote_calls
194+
assert {28, Record, :is_record, 1} in compile_remote_calls
195+
assert {30, Macro.Env, :__struct__, 1} in compile_remote_calls
196+
assert {32, Kernel.LexicalTracker, :remote_dispatches, 1} in compile_remote_calls
192197

193198
runtime_remote_calls = unroll_dispatches(runtime_remote_calls)
194199
assert {7, Record, :extract, 2} in runtime_remote_calls
@@ -200,7 +205,7 @@ defmodule Kernel.LexicalTrackerTest do
200205
assert {16, Remote, :func, 0} in runtime_remote_calls
201206
assert {17, Remote, :func, 0} in runtime_remote_calls
202207
assert {18, :erlang, :==, 2} in runtime_remote_calls
203-
assert {27, :erlang, :is_tuple, 1} in runtime_remote_calls
208+
assert {28, :erlang, :is_tuple, 1} in runtime_remote_calls
204209
end
205210

206211
defp unroll_dispatches(dispatches) do

0 commit comments

Comments
 (0)