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:
LemonBoy 2018-06-24 18:27:40 +02:00
commit 9543689306
2 changed files with 11 additions and 0 deletions

View file

@ -1772,7 +1772,9 @@ proc semStaticStmt(c: PContext, n: PNode): PNode =
#echo "semStaticStmt"
#writeStackTrace()
inc c.inStaticContext
openScope(c)
let a = semStmt(c, n.sons[0])
closeScope(c)
dec c.inStaticContext
n.sons[0] = a
evalStaticStmt(c.module, c.graph, a, c.p.owner)

9
tests/global/t5958.nim Normal file
View file

@ -0,0 +1,9 @@
discard """
line: 9
errormsg: "undeclared identifier: 'a'"
"""
static:
var a = 1
echo a