Files
Nim/tests/vm/tconstscope2.nim
metagn a6595e5b49 open new scope for const values (#24084)
fixes #5395

Previously values of `const` statements used the same scope as the
`const` statement itself, meaning variables could be declared inside
them and referred to in other statements in the same block. Now each
`const` value opens its own scope, so any variable declared in the value
of a constant can only be accessed for that constant.

We could change this to open a new scope for the `const` *section*
rather than each constant, so the variables can be used in other
constants, but I'm not sure if this is sound.
2024-09-09 11:29:30 +02:00

6 lines
109 B
Nim

const
a = (var x = 3; x)
# should we allow this?
b = x #[tt.Error
^ undeclared identifier: 'x']#