diff options
-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 |