Make static blocks introduce their own scope
Treat the static block as a normal block, don't leak any identifier in the outer scope. Fixes #5958
This commit is contained in:
parent
105a472dc5
commit
9543689306
2 changed files with 11 additions and 0 deletions
|
|
@ -1772,7 +1772,9 @@ proc semStaticStmt(c: PContext, n: PNode): PNode =
|
||||||
#echo "semStaticStmt"
|
#echo "semStaticStmt"
|
||||||
#writeStackTrace()
|
#writeStackTrace()
|
||||||
inc c.inStaticContext
|
inc c.inStaticContext
|
||||||
|
openScope(c)
|
||||||
let a = semStmt(c, n.sons[0])
|
let a = semStmt(c, n.sons[0])
|
||||||
|
closeScope(c)
|
||||||
dec c.inStaticContext
|
dec c.inStaticContext
|
||||||
n.sons[0] = a
|
n.sons[0] = a
|
||||||
evalStaticStmt(c.module, c.graph, a, c.p.owner)
|
evalStaticStmt(c.module, c.graph, a, c.p.owner)
|
||||||
|
|
|
||||||
9
tests/global/t5958.nim
Normal file
9
tests/global/t5958.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
discard """
|
||||||
|
line: 9
|
||||||
|
errormsg: "undeclared identifier: 'a'"
|
||||||
|
"""
|
||||||
|
|
||||||
|
static:
|
||||||
|
var a = 1
|
||||||
|
|
||||||
|
echo a
|
||||||
Loading…
Add table
Add a link
Reference in a new issue