Merge pull request #8108 from LemonBoy/fix-5958
Make `static` blocks introduce their own scope
This commit is contained in:
commit
ccb1514837
5 changed files with 23 additions and 15 deletions
|
|
@ -1779,7 +1779,9 @@ proc semStaticStmt(c: PContext, n: PNode): PNode =
|
||||||
#echo "semStaticStmt"
|
#echo "semStaticStmt"
|
||||||
#writeStackTrace()
|
#writeStackTrace()
|
||||||
inc c.inStaticContext
|
inc c.inStaticContext
|
||||||
|
openScope(c)
|
||||||
let a = semStmt(c, n.sons[0])
|
let a = semStmt(c, n.sons[0])
|
||||||
|
closeScope(c)
|
||||||
dec c.inStaticContext
|
dec c.inStaticContext
|
||||||
n.sons[0] = a
|
n.sons[0] = a
|
||||||
evalStaticStmt(c.module, c.graph, a, c.p.owner)
|
evalStaticStmt(c.module, c.graph, a, c.p.owner)
|
||||||
|
|
|
||||||
9
tests/global/t5958.nim
Normal file
9
tests/global/t5958.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
discard """
|
||||||
|
line: 9
|
||||||
|
errormsg: "undeclared identifier: 'a'"
|
||||||
|
"""
|
||||||
|
|
||||||
|
static:
|
||||||
|
var a = 1
|
||||||
|
|
||||||
|
echo a
|
||||||
|
|
@ -71,5 +71,4 @@ macro make(arg: untyped): untyped =
|
||||||
proc first(i: int): void =
|
proc first(i: int): void =
|
||||||
make(second)
|
make(second)
|
||||||
|
|
||||||
static:
|
var ss {.compileTime.}: string = ""
|
||||||
var ss: string = ""
|
|
||||||
|
|
@ -4,14 +4,12 @@ proc assertEq(arg0,arg1: string): void =
|
||||||
if arg0 != arg1:
|
if arg0 != arg1:
|
||||||
raiseAssert("strings not equal:\n" & arg0 & "\n" & arg1)
|
raiseAssert("strings not equal:\n" & arg0 & "\n" & arg1)
|
||||||
|
|
||||||
static:
|
|
||||||
# a simple assignment of stmtList to another variable
|
# a simple assignment of stmtList to another variable
|
||||||
var node: NimNode
|
var node {.compileTime.}: NimNode
|
||||||
# an assignment of stmtList into an array
|
# an assignment of stmtList into an array
|
||||||
var nodeArray: array[1, NimNode]
|
var nodeArray {.compileTime.}: array[1, NimNode]
|
||||||
# an assignment of stmtList into a seq
|
# an assignment of stmtList into a seq
|
||||||
var nodeSeq = newSeq[NimNode](2)
|
var nodeSeq {.compileTime.} = newSeq[NimNode](2)
|
||||||
|
|
||||||
|
|
||||||
proc checkNode(arg: NimNode; name: string): void {. compileTime .} =
|
proc checkNode(arg: NimNode; name: string): void {. compileTime .} =
|
||||||
echo "checking ", name
|
echo "checking ", name
|
||||||
|
|
@ -35,10 +33,10 @@ proc checkNode(arg: NimNode; name: string): void {. compileTime .} =
|
||||||
|
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
|
||||||
static:
|
|
||||||
# the root node that is used to generate the Ast
|
# the root node that is used to generate the Ast
|
||||||
var stmtList: NimNode
|
var stmtList {.compileTime.}: NimNode
|
||||||
|
|
||||||
|
static:
|
||||||
stmtList = newStmtList(nnkDiscardStmt.newTree(newEmptyNode()))
|
stmtList = newStmtList(nnkDiscardStmt.newTree(newEmptyNode()))
|
||||||
|
|
||||||
checkNode(stmtList, "direct construction")
|
checkNode(stmtList, "direct construction")
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ block:
|
||||||
var x = default(type(0))
|
var x = default(type(0))
|
||||||
|
|
||||||
# #6379
|
# #6379
|
||||||
static:
|
|
||||||
import algorithm
|
import algorithm
|
||||||
|
|
||||||
|
static:
|
||||||
var numArray = [1, 2, 3, 4, -1]
|
var numArray = [1, 2, 3, 4, -1]
|
||||||
numArray.sort(cmp)
|
numArray.sort(cmp)
|
||||||
assert numArray == [-1, 1, 2, 3, 4]
|
assert numArray == [-1, 1, 2, 3, 4]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue