From e89aaaeaab40088eb57a0209e152e90ce16ed51c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 23 Feb 2019 12:05:07 +0100 Subject: [PATCH] Open a new scope for `static:` expr blocks (#10649) Bring this in line with how plain blocks are analysed and avoids codegen errors if one references variables defined in such a block. --- compiler/semexprs.nim | 6 +++++- tests/errmsgs/tstaticexprnotype.nim | 5 +++++ tests/errmsgs/tstaticexprscope.nim | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/tstaticexprnotype.nim create mode 100644 tests/errmsgs/tstaticexprscope.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 7bd40a9543..f66ec70624 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -735,7 +735,11 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode = # echo "SUCCESS evaluated at compile time: ", call.renderTree proc semStaticExpr(c: PContext, n: PNode): PNode = - let a = semExpr(c, n) + inc c.inStaticContext + openScope(c) + let a = semExprWithType(c, n) + closeScope(c) + dec c.inStaticContext if a.findUnresolvedStatic != nil: return a result = evalStaticExpr(c.module, c.graph, a, c.p.owner) if result.isNil: diff --git a/tests/errmsgs/tstaticexprnotype.nim b/tests/errmsgs/tstaticexprnotype.nim new file mode 100644 index 0000000000..8b6735ff80 --- /dev/null +++ b/tests/errmsgs/tstaticexprnotype.nim @@ -0,0 +1,5 @@ +discard """ + action: reject +""" + +let x = static: discard diff --git a/tests/errmsgs/tstaticexprscope.nim b/tests/errmsgs/tstaticexprscope.nim new file mode 100644 index 0000000000..7af5bf9b37 --- /dev/null +++ b/tests/errmsgs/tstaticexprscope.nim @@ -0,0 +1,11 @@ +discard """ + errmsg: "undeclared identifier: 'z'" + line: 11 +""" + +# Open a new scope for static expr blocks +block: + let a = static: + var z = 123 + 33 + echo z