-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix error message when using const
inside a function, require the LHS to be global, and prohibit "const x[] = 1"
#57470
base: master
Are you sure you want to change the base?
Conversation
0f5a7aa
to
5a09ce3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Minor nit with this error though:
julia> const (x{T},) = T
ERROR: syntax: `const` left hand side "SSAValue(81)" contains non-variables around REPL[13]:1
Argh, this is actually a regression. 1.11.3:
This:
I'll need to think of a way to handle this. |
Also update some tests that used @test with a quote containing `const`, which cannot be spliced into a function.
33184ba
to
b45c8e0
Compare
Also update some tests that used @test with a quote containing `const`, which cannot be spliced into a function.
b45c8e0
to
a4f7d00
Compare
Also update some tests that used @test with a quote containing `const`, which cannot be spliced into a function.
a4f7d00
to
ce76dbf
Compare
This is a note to myself to not squash 9fe9bbe so I am not git blame'd for all of the assignment lowering code. |
@nanosoldier |
Linking #25642 |
The package evaluation job you requested has completed - possible new issues were detected. Report summary❗ Packages that crashed1 packages crashed only on the current version.
13 packages crashed on the previous version too. ✖ Packages that failed24 packages failed only on the current version.
1109 packages failed on the previous version too. ✔ Packages that passed tests27 packages passed tests only on the current version.
5330 packages passed tests on the previous version too. ~ Packages that at least loaded7 packages successfully loaded only on the current version.
2926 packages successfully loaded on the previous version too. ➖ Packages that were skipped altogether899 packages were skipped on the previous version too. |
@@ -3126,7 +3152,7 @@ | |||
((eq? (car e) 'assign-const-if-global) | |||
(if (eq? (var-kind (cadr e) scope) 'local) | |||
(if (length= e 2) (null) `(= ,@(cdr e))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if (length= e 2) (null) `(= ,@(cdr e))) | |
(if (length= e 2) (null) (resolve-scopes- `(= ,@(cdr e)) scope sp loc)) |
would fix #57574 (suggested here since you've already done this to the other branch).
Also update some tests that used @test with a quote containing `const`, which cannot be spliced into a function.
Modifies the handling of the 3-argument "lowered const" so `const x = y` participates in scope resolution again (JuliaLang#56613); we treat (const x y) as an assignment form, producing the "unsupported `const` declaration on local variable" error if the usual scope rules would not make x global. At the top level, these should succeed: const x = 1 begin const x = 1 end let const global x = 1 end Each of the following should fail: # ERROR: syntax: unsupported `const` declaration on local variable around REPL[1]:2 let const x = 1 end # ERROR: syntax: unsupported `const` declaration on local variable around REPL[1]:2 function f() const x = 1 end This also amkes the use of `const global` inside a function body produce the original, specific error message rather than a generic "World age increment not at top level" error (JuliaLang#57334): # ERROR: syntax: `global const` declaration not allowed inside function around REPL[1]:2 function f() global const x = 1 end Issue JuliaLang#57334 revealed we silently accept `const` expressions writing to variables. These now fail with a new error message: a = [1, 2] # ERROR: syntax: cannot declare "a[1]" `const` around REPL[1]:2 const a[1] = 3 The bulk of these changes track const-ness through the functions called by expand-assignment, since each of the three types of LHS is affect differently: - ordinary variables become `const`, producing error if not global - `X{T} = ...` forces X to be `const`, rather than the defaulting to being implicitly const only if in global scope. - `f() = ...` ignores `const`.
ce76dbf
to
14c14f1
Compare
The changes to
const
resulted in confusing error messages when it was usedinside a function (#57334). On 1.11.3:
On nightly:
In prior versions, we also accepted confused expressions like:
This change adds a new error messages explicitly prohibiting
const
where theleft hand side is not declaring variables:
Finally, #54773 made
const
stop participating in scope resolution (the lefthand side was always taken to be in global scope). Some expressions that were
prohibited started being accepted:
In 1.11.3:
Nightly:
This change rejects
const
unless the variable would be in global scope(
global const
would be required in the example), so we don't lose theability to make
const
in local scope meaningful later.