Skip to content

const semantics changed to implicitly global in 1.12-DEV #56613

@c42f

Description

@c42f

In Julia 1.11, using const in front of a variable implied neither local nor global semantics - rather the scope was calculated according to the usual rules:

julia> Meta.@lower function f()
           const x = 1
       end
:($(Expr(:error, "unsupported `const` declaration on local variable around REPL[1]:2")))

julia> let
           const x = 1
       end
ERROR: syntax: unsupported `const` declaration on local variable around REPL[2]:2

However, in 1.12 dev, as of #54773, it seems that const implicitly implies global:

julia> Meta.@lower function f()
           const x = 1
       end
:($(Expr(:error, "`global const` declaration not allowed inside function around REPL[3]:2")))

julia> let
           const x = 1
       end
1

julia> x
1

This seems like a significant semantic change which I'm not convinced is a good idea. If one wants a global variable within a let block at top level, I think the user should explicitly declare global const x = 1 in the example above.

@Keno is this a bug or was it intentional?

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)regressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions