You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original reporter: michalmuskala
Affected version: OTP-23.0
Fixed in version: OTP-24.0
Component: compiler
Migrated from: https://bugs.erlang.org/browse/ERL-1380
The following program compiles fine, treating the repeated appearance of variable {{Repeat}} as distinct (the variable is bound to the value of the stacktrace).
{code:erlang}
-module(test).
-compile(export_all).
t(F) ->
try F()
catch
_:Repeat:Repeat -> Repeat
end.
{code}
This should be refused by the compiler and an error issued saying the stacktrace variable can't be reused in the pattern.
The text was updated successfully, but these errors were encountered:
A clarifying point (after talking to Michal): we never want to allow pattern matching on the Trace field, since it would force us to first reify the trace as a term, which is quite costly. The reification should only happen if the clause actually matches and the user accesses the Trace variable.
Hence, the Trace variable must not be bound before the catch clause, and the compiler already generates an error if you do something like Trace=..., {{try ... catch Class:Term:Trace -> ... end}}
However, if an unbound variable has multiple instances X, X~1~, X~2~, ... in a clause head, it means that these must have the same value, and the compiler must add guard tests X =:= X~1~, X =:= X~2~ to ensure that the clause only is selected if this is true.
In catch clauses such as {{try ... catch _:T:T -> ... end}} the compiler misses this, effectively treating the two {{T}} as different variables. This is a bug. But we don't want the standard behaviour either, because it would force us to reify the trace as a term before we could execute the added guard tests. Therefore, it must be an error to have multiple instances of the trace variable in the head.
Original reporter:
michalmuskala
Affected version:
OTP-23.0
Fixed in version:
OTP-24.0
Component:
compiler
Migrated from: https://bugs.erlang.org/browse/ERL-1380
The text was updated successfully, but these errors were encountered: