Skip to content

Commit 2fc9160

Browse files
committed
Rewrite stacktraces for compatibility with upcoming OTP version
1 parent 9a428e9 commit 2fc9160

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/elixir/src/elixir_dispatch.erl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ dispatch_import(Meta, Name, Args, E, Callback) ->
9797
Callback()
9898
end.
9999

100+
dispatch_require(Meta, 'Elixir.System', stacktrace, [], #{contextual_vars := Vars} = E, Callback) ->
101+
case lists:member('__STACKTRACE__', Vars) of
102+
true ->
103+
{{'__STACKTRACE__', [], nil}, E};
104+
false ->
105+
Message =
106+
"System.stacktrace/0 outside of rescue/catch clauses is deprecated. "
107+
"If you want to support only Elixir v1.7+, you must access __STACKTRACE__ "
108+
"inside a rescue/catch. If you want to support earlier Elixir versions, "
109+
"move System.stacktrace/0 inside a rescue/catch",
110+
elixir_errors:erl_warn(?line(Meta), ?key(E, file), Message),
111+
Callback('Elixir.System', stacktrace, [])
112+
end;
113+
100114
dispatch_require(Meta, Receiver, Name, Args, E, Callback) when is_atom(Receiver) ->
101115
Arity = length(Args),
102116

@@ -353,18 +367,6 @@ check_deprecated(_, erlang, _, _, _) ->
353367
ok;
354368
check_deprecated(_, _, _, _, #{module := 'Elixir.HashDict'}) ->
355369
ok;
356-
check_deprecated(Meta, 'Elixir.System', stacktrace, 0, #{contextual_vars := Vars} = E) ->
357-
case lists:member('__STACKTRACE__', Vars) of
358-
true ->
359-
ok;
360-
false ->
361-
Message =
362-
"System.stacktrace/0 outside of rescue/catch clauses is deprecated. "
363-
"If you want to support only Elixir v1.7+, you must access __STACKTRACE__ "
364-
"inside a rescue/catch. If you want to support earlier Elixir versions, "
365-
"move System.stacktrace/0 inside a rescue/catch",
366-
elixir_errors:erl_warn(?line(Meta), ?key(E, file), Message)
367-
end;
368370
check_deprecated(Meta, Receiver, Name, Arity, E) ->
369371
case (?key(E, function) == nil) andalso is_ensure_loaded(Receiver) of
370372
true ->

0 commit comments

Comments
 (0)