mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 05:23:20 +00:00
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.
This commit is contained in:
@@ -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:
|
||||
|
||||
5
tests/errmsgs/tstaticexprnotype.nim
Normal file
5
tests/errmsgs/tstaticexprnotype.nim
Normal file
@@ -0,0 +1,5 @@
|
||||
discard """
|
||||
action: reject
|
||||
"""
|
||||
|
||||
let x = static: discard
|
||||
11
tests/errmsgs/tstaticexprscope.nim
Normal file
11
tests/errmsgs/tstaticexprscope.nim
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user