-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Is try-catch scoping as hard as let and for? #34668
Comments
|
That's what I meant to say. Shouldn't the exception variable ( |
I suppose that does seem quite similar to the loop variable in a for loop. cc @JeffBezanson |
Yes, I agree the catch block var should be let-bound. I was surprised to see (this really seems like a mistake of some sort) that we just lower this to a plain assignment. So for example
That can't have been what we intended, but technically this is a breaking change. |
Actually, I sometimes write code that relies on it. Something like @testcase begin
err = nothing
@test try
f()
false
catch err
true
end
@test occursin("some error message", sprint(showerror, err))
end I thought it was weird but I didn't think carefully back then when I started using it. (Before this I was using I personally prefer "tightening" the scope (so breaking the above code) but I'd imagine someone else might be using it already due to Hyrum's law. But if it is only me by some kind of miracle, please go ahead and change it :) |
Definitely worth a PkgEval run to see if it breaks much. Hopefully not! |
Given that
let x
andfor x in ...
introduce a hard-scope forx
, I find that it's inconsistent that the scoping oftry ... catch err; ... end
is ambiguous.But I couldn't follow all the comments in #33864 and related issues so I may be missing something. I only found that it was explicitly decided that
let
uses a hard-scope #33864 (comment).MWE:
The text was updated successfully, but these errors were encountered: