Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERL-1380: Repeated stacktrace variable not refused #4368

Closed
OTP-Maintainer opened this issue Oct 13, 2020 · 4 comments
Closed

ERL-1380: Repeated stacktrace variable not refused #4368

OTP-Maintainer opened this issue Oct 13, 2020 · 4 comments
Assignees
Labels
bug Issue is reported as a bug priority:medium team:VM Assigned to OTP team VM
Milestone

Comments

@OTP-Maintainer
Copy link

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.
@OTP-Maintainer
Copy link
Author

richardc said:

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.

 

@OTP-Maintainer
Copy link
Author

bjorn said:

Yes, I understood what was meant, but I haven't got around to fixing the bug yet.

@OTP-Maintainer
Copy link
Author

richardc said:

We have a fix in preparation already.

@OTP-Maintainer
Copy link
Author

lukas said:

See https://github.com/erlang/otp/pull/2944 for PR

@OTP-Maintainer OTP-Maintainer added bug Issue is reported as a bug team:VM Assigned to OTP team VM priority:medium labels Feb 10, 2021
@OTP-Maintainer OTP-Maintainer added this to the OTP-24.0 milestone Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug priority:medium team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

2 participants