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

for 2.0, make try/catch/else/finally scopeless? #48434

Open
StefanKarpinski opened this issue Jan 27, 2023 · 2 comments
Open

for 2.0, make try/catch/else/finally scopeless? #48434

StefanKarpinski opened this issue Jan 27, 2023 · 2 comments
Labels
breaking This change will break code speculative Whether the change will be implemented is speculative
Milestone

Comments

@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Jan 27, 2023

There's been a number of complaints over the years about the fact that each clause of a try/catch/else/finally construct introduces new local scope. This means that if you assign something in the try clause it won't be visible afterwards. But moreover, it won't be visible in the catch, else or finally blocks. The lack of visibility in catch block is and after the whole try construct is somewhat justifiable since we don't want to by default leave undefined variables (although it is easy enough to do with something like if cond(); x = 1; end. Perhaps it would be simpler and easier if the whole try construct didn't introduce any local scopes? Similar to how if/else doesn't. Just a thought. Reference example issue: #46928.

@StefanKarpinski StefanKarpinski added speculative Whether the change will be implemented is speculative breaking This change will break code labels Jan 27, 2023
@StefanKarpinski StefanKarpinski added this to the 2.0 milestone Jan 27, 2023
@IanButterworth
Copy link
Sponsor Member

Aside from changing the default behavior, triage approved of a @noscope macro (#39217) for making a try etc. work like this, but I stalled because I think to do it properly requires deeper understanding of the interpreter

@PallHaraldsson
Copy link
Contributor

try-clauses are pretty fundamental, and something we want the right semantics for. While this is breaking, would a lot of code out there likely NOT break (such as none in the standard library)? [And with this change would a macro for the opposite, the old, behavior be needed, except for compatibility?]

Do we want to do Julia 2.0, sooner rather than later because of this? I guess for a while we would want a switch to opt into older behavior (for the same Julia 2.x binaries and/or display a warning for some code where behavior will change).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

3 participants