diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2019-02-23 12:05:07 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-02-23 12:05:07 +0100 |
commit | e89aaaeaab40088eb57a0209e152e90ce16ed51c (patch) | |
tree | 548ddfccc533ca49b287aac176f9dd333dc52e39 | |
parent | f86835ce77f05133cdb8eeef0a7986a040a61954 (diff) | |
download | Nim-e89aaaeaab40088eb57a0209e152e90ce16ed51c.tar.gz |
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.
-rw-r--r-- | compiler/semexprs.nim | 6 | ||||
-rw-r--r-- | tests/errmsgs/tstaticexprnotype.nim | 5 | ||||
-rw-r--r-- | tests/errmsgs/tstaticexprscope.nim | 11 |
3 files changed, 21 insertions, 1 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 7bd40a954..f66ec7062 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 000000000..8b6735ff8 --- /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 000000000..7af5bf9b3 --- /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 |