-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit fb01f91
authored
Fix error message when using
The changes to `const` resulted in confusing error messages when it was
used inside a function (#57334). On 1.11.3:
```
julia> function f()
const x = 1
end
ERROR: syntax: unsupported `const` declaration on local variable around REPL[1]:2
Stacktrace:
[1] top-level scope
@ REPL[1]:1
```
On nightly:
```
julia> function f()
const x = 1
end
ERROR: syntax: World age increment not at top level
Stacktrace:
[1] top-level scope
@ REPL[1]:1
```
In prior versions, we also accepted confused expressions like:
```
x = Ref(1)
const x[] = 1
```
This change adds a new error messages explicitly prohibiting `const`
where the left hand side is not declaring variables:
```
ERROR: syntax: `const` left hand side "x[]" contains non-variables around REPL[2]:1
Stacktrace:
[1] top-level scope
@ REPL[2]:1
```
Finally, #54773 made `const` stop participating in scope resolution
(the left hand side was always taken to be in global scope). Some
expressions that were prohibited started being accepted:
In 1.11.3:
```
julia> let
const x = 1
end
ERROR: syntax: unsupported `const` declaration on local variable around REPL[1]:2
Stacktrace:
[1] top-level scope
@ REPL[1]:1
```
Nightly:
```
julia> let
const x = 1
end
1
```
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 the ability to make `const` in local scope meaningful later.const
inside a function, require the LHS to be global, and prohibit "const x[] = 1" (#57470)2 files changed
+315
-177
lines changed
0 commit comments