-
-
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
unreachable code interacts with scoping rules and changes program behavior #56874
Comments
It should change the scope from a local in the let block and a different global in the isdefined test, to a local over the whole function, though I don't think that should have changed the result as observed |
The presence of the assignment later in the scope declares it as a local variable for the entire scope. In the |
I understand @Keno that that's what the behavior would be if the assignment was not in an let
let
admit_guilt = true
end
if @isdefined(admit_guilt)
admit_guilt && println("I'm guilty. But you're never going to know. Unless you've messed with time travel.")
else
println("I'm not guilty.")
if false # code inside this block never executes
println("a secret never spilled")
admit_guilt = false #---------------- unleash me ---------EDITED
end
end
@assert admit_guilt #------------------------------------------EDITED
end More importantly, @vtjnash, are you closing the issue because the current behavior is correct and expected, or because it is unfortunate but there is not much we can do about it, or something else? |
Scoping rules are static and not path sensitive, so the |
The code below prints:
If you uncomment the line marked
unleash me
, it prints:It reminds me of this #5148 (comment) , but I think there, the inner functions are getting pulled out and getting defined in the global scope (maybe?). I'm not sure what's going on here.
The text was updated successfully, but these errors were encountered: