From 95436893061176d51b1c11fdf5418b3ed17a8455 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 24 Jun 2018 18:27:40 +0200 Subject: [PATCH] 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 --- compiler/semstmts.nim | 2 ++ tests/global/t5958.nim | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/global/t5958.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 292238dc9..fe4318de5 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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) diff --git a/tests/global/t5958.nim b/tests/global/t5958.nim new file mode 100644 index 000000000..5abcad4a9 --- /dev/null +++ b/tests/global/t5958.nim @@ -0,0 +1,9 @@ +discard """ + line: 9 + errormsg: "undeclared identifier: 'a'" +""" + +static: + var a = 1 + +echo a