-
-
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
UndefVarError if trying to shadow global variable using let #50369
Comments
No I don't think this is considered a bug, this is a core part of how name resolution works in julia. When you write let ex1 = ex2
...
end
let
ex1 = ex2
end that both |
During definition of Similarly, even the following continuation of my example would be illegal, which it is clearly not.
|
No, because |
I think the behaviour being requested would be a somewhat reasonable thing for us to do, and I think it’s fine to keep the issue open as a feature request. My point was just that it’s not really a bug. as far as I’m aware this is understood and intended behaviour. |
Record the 'scope' of the variable that was undefined (the Module, or a descriptive word such as :local or :static_parameter). Add that scope to the error message, and expand the hint suggestions added by the REPL to include more specific advice on common mistakes: - forgetting to set an initial value - forgetting to import a global - creating a local of the same name as a global - not matching a static parameter in a signature subtype Fixes #17062 (although more could probably be done to search for typos using REPL.string_distance and getting the method from stacktrace) Fixes #18877 Fixes #25263 Fixes #35126 Fixes #39280 Fixes #41728 Fixes #48731 Fixes #49917 Fixes #50369
Record the 'scope' of the variable that was undefined (the Module, or a descriptive word such as :local or :static_parameter). Add that scope to the error message, and expand the hint suggestions added by the REPL to include more specific advice on common mistakes: - forgetting to set an initial value - forgetting to import a global - creating a local of the same name as a global - not matching a static parameter in a signature subtype Fixes #17062 (although more could probably be done to search for typos using REPL.string_distance and getting the method from stacktrace) Fixes #18877 Fixes #25263 Fixes #35126 Fixes #39280 Fixes #41728 Fixes #48731 Fixes #49917 Fixes #50369
When working with Pluto, I like to wrap more complex cells using
let
and reuse simple variable names.Within Pluto, everything works fine, but when executing the notebook as a standalone script, Julia complains about some variables not being defined.
MWE
Workaround
By removing the initial line break, Julia gets what I mean.
But I think this is a bug of Julia (and I don't want to use different variable names or edit the whole already-too-long notebook). 🙃
The text was updated successfully, but these errors were encountered: