Skip to content

Commit 247fd71

Browse files
committed
Emit trace events for super calls, closes #14395
1 parent bb8761a commit 247fd71

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

Diff for: lib/elixir/src/elixir_expand.erl

+5-4
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ expand({'&', Meta, [{'/', ArityMeta, [{super, SuperMeta, Context}, Arity]} = Exp
297297

298298
case resolve_super(Meta, Arity, E) of
299299
{Kind, Name, _} when Kind == def; Kind == defp ->
300-
{{'&', Meta, [{'/', ArityMeta, [{Name, SuperMeta, Context}, Arity]}]}, S, E};
300+
expand({'&', Meta, [{'/', ArityMeta, [{Name, SuperMeta, Context}, Arity]}]}, S, E);
301301
_ ->
302302
expand_fn_capture(Meta, Expr, S, E)
303303
end;
@@ -347,7 +347,9 @@ expand({with, Meta, [_ | _] = Args}, S, E) ->
347347

348348
expand({super, Meta, Args}, S, E) when is_list(Args) ->
349349
assert_no_match_or_guard_scope(Meta, "super", S, E),
350-
{Kind, Name, _} = resolve_super(Meta, length(Args), E),
350+
Arity = length(Args),
351+
{Kind, Name, _} = resolve_super(Meta, Arity, E),
352+
elixir_env:trace({local_function, Meta, Name, Arity}, E),
351353
{EArgs, SA, EA} = expand_args(Args, S, E),
352354
{{super, [{super, {Kind, Name}} | Meta], EArgs}, SA, EA};
353355

@@ -903,8 +905,7 @@ expand_local(Meta, Name, Args, S, #{function := Function, context := Context} =
903905
module_error(Meta, E, ?MODULE, {invalid_local_invocation, elixir_utils:guard_info(S), {Name, Meta, Args}});
904906

905907
nil ->
906-
Arity = length(Args),
907-
elixir_env:trace({local_function, Meta, Name, Arity}, E)
908+
elixir_env:trace({local_function, Meta, Name, length(Args)}, E)
908909
end,
909910

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

Diff for: lib/elixir/test/elixir/kernel/tracers_test.exs

+28
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,34 @@ defmodule Kernel.TracersTest do
278278
assert meta[:from_brackets]
279279
end
280280

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

0 commit comments

Comments
 (0)