Skip to content

Commit ab17a3c

Browse files
committed
Emit trace events for super calls, closes #14395
1 parent 2522bba commit ab17a3c

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/elixir/src/elixir_expand.erl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ expand({'&', Meta, [{'/', ArityMeta, [{super, SuperMeta, Context}, Arity]} = Exp
293293

294294
case resolve_super(Meta, Arity, E) of
295295
{Kind, Name, _} when Kind == def; Kind == defp ->
296-
{{'&', Meta, [{'/', ArityMeta, [{Name, SuperMeta, Context}, Arity]}]}, S, E};
296+
expand({'&', Meta, [{'/', ArityMeta, [{Name, SuperMeta, Context}, Arity]}]}, S, E);
297297
_ ->
298298
expand_fn_capture(Meta, Expr, S, E)
299299
end;
@@ -343,7 +343,9 @@ expand({with, Meta, [_ | _] = Args}, S, E) ->
343343

344344
expand({super, Meta, Args}, S, E) when is_list(Args) ->
345345
assert_no_match_or_guard_scope(Meta, "super", S, E),
346-
{Kind, Name, _} = resolve_super(Meta, length(Args), E),
346+
Arity = length(Args),
347+
{Kind, Name, _} = resolve_super(Meta, Arity, E),
348+
elixir_env:trace({local_function, Meta, Name, Arity}, E),
347349
{EArgs, SA, EA} = expand_args(Args, S, E),
348350
{{super, [{super, {Kind, Name}} | Meta], EArgs}, SA, EA};
349351

@@ -899,8 +901,7 @@ expand_local(Meta, Name, Args, S, #{function := Function, context := Context} =
899901
module_error(Meta, E, ?MODULE, {invalid_local_invocation, elixir_utils:guard_info(S), {Name, Meta, Args}});
900902

901903
nil ->
902-
Arity = length(Args),
903-
elixir_env:trace({local_function, Meta, Name, Arity}, E)
904+
elixir_env:trace({local_function, Meta, Name, length(Args)}, E)
904905
end,
905906

906907
{EArgs, SA, EA} = expand_args(Args, S, E),

lib/elixir/test/elixir/kernel/tracers_test.exs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,34 @@ defmodule Kernel.TracersTest do
274274
assert meta[:from_brackets]
275275
end
276276

277+
test "traces super" do
278+
compile_string("""
279+
defmodule TracerOverridable do
280+
def local(x), do: x
281+
defoverridable [local: 1]
282+
def local(x), do: super(x)
283+
284+
defmacro macro(x), do: x
285+
defoverridable [macro: 1]
286+
defmacro macro(x), do: super(x)
287+
288+
def capture(x), do: x
289+
defoverridable [capture: 1]
290+
def capture(x), do: tap(x, &super/1)
291+
292+
def capture_arg(x), do: x
293+
defoverridable [capture_arg: 1]
294+
def capture_arg(x), do: tap(x, &super(&1))
295+
end
296+
""")
297+
298+
assert_received {{:local_function, _, :"local (overridable 1)", 1}, _}
299+
assert_received {{:local_function, _, :"macro (overridable 1)", 1}, _}
300+
assert_received {{:local_function, _, :"capture (overridable 1)", 1}, _}
301+
assert_received {{:local_function, _, :"capture_arg (overridable 1)", 1}, _}
302+
refute_received {{:local_function, _, _, _}, _}
303+
end
304+
277305
test "does not trace bind quoted twice" do
278306
compile_string("""
279307
quote bind_quoted: [foo: List.flatten([])] do

0 commit comments

Comments
 (0)