Skip to content

make const a toplevel expr or error #12010

@vtjnash

Description

@vtjnash

const can cause serious, subtle bugs when combined with precompilation. it is valid to use from the :toplevel scope, but it can cause problems if used at runtime (and it's already ignored when specified at the local scope. this could be fixed by warning for and ignoring the const declaration outside of the toplevel scope. or this could be fixed by internally distinguishing between const (as it is currently defined) and a new assigned once attribute (that provides none of the inference speed benefits of const, but just doesn't allow reassignment).

the following is fine:

module Fine
const binding = value
end

the following can confuse precompilation (and isn't great for type inference either):

module Bad
__init__() = (global const binding = value)
end

the following currently is ignored by parsing, so is neither bad nor good:

module Either
f() = (const localb = localv)
end

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions