mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 19:22:40 +00:00
fixes #5417
This commit is contained in:
@@ -540,7 +540,7 @@ proc genBreakStmt(p: BProc, t: PNode) =
|
||||
# named break?
|
||||
assert(t.sons[0].kind == nkSym)
|
||||
var sym = t.sons[0].sym
|
||||
assert(sym.loc.k == locOther)
|
||||
doAssert(sym.loc.k == locOther)
|
||||
idx = sym.position-1
|
||||
else:
|
||||
# an unnamed 'break' can only break a loop after 'transf' pass:
|
||||
|
||||
@@ -2107,7 +2107,7 @@ proc semBlock(c: PContext, n: PNode): PNode =
|
||||
var labl = newSymG(skLabel, n.sons[0], c)
|
||||
if sfGenSym notin labl.flags:
|
||||
addDecl(c, labl)
|
||||
n.sons[0] = newSymNode(labl, n.sons[0].info)
|
||||
n.sons[0] = newSymNode(labl, n.sons[0].info)
|
||||
suggestSym(n.sons[0].info, labl)
|
||||
styleCheckDef(labl)
|
||||
n.sons[1] = semExpr(c, n.sons[1])
|
||||
|
||||
@@ -30,6 +30,7 @@ proc semBreakOrContinue(c: PContext, n: PNode): PNode =
|
||||
of nkIdent: s = lookUp(c, n.sons[0])
|
||||
of nkSym: s = n.sons[0].sym
|
||||
else: illFormedAst(n)
|
||||
s = getGenSym(c, s)
|
||||
if s.kind == skLabel and s.owner.id == c.p.owner.id:
|
||||
var x = newSymNode(s)
|
||||
x.info = n.info
|
||||
|
||||
@@ -384,11 +384,13 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||
checkSonsLen(n, 2)
|
||||
openScope(c)
|
||||
if n.sons[0].kind != nkEmpty:
|
||||
# labels are always 'gensym'ed:
|
||||
let s = newGenSym(skLabel, n.sons[0], c)
|
||||
addPrelimDecl(c.c, s)
|
||||
styleCheckDef(s)
|
||||
n.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
addLocalDecl(c, n.sons[0], skLabel)
|
||||
when false:
|
||||
# labels are always 'gensym'ed:
|
||||
let s = newGenSym(skLabel, n.sons[0], c)
|
||||
addPrelimDecl(c.c, s)
|
||||
styleCheckDef(s)
|
||||
n.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
n.sons[1] = semTemplBody(c, n.sons[1])
|
||||
closeScope(c)
|
||||
of nkTryStmt:
|
||||
|
||||
18
tests/template/tgensym_label.nim
Normal file
18
tests/template/tgensym_label.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
# bug #5417
|
||||
import macros
|
||||
|
||||
macro genBody: untyped =
|
||||
let sbx = genSym(nskLabel, "test")
|
||||
when true:
|
||||
result = quote do:
|
||||
block `sbx`:
|
||||
break `sbx`
|
||||
else:
|
||||
template foo(s1, s2) =
|
||||
block s1:
|
||||
break s2
|
||||
result = getAst foo(sbx, sbx)
|
||||
|
||||
proc test() =
|
||||
genBody()
|
||||
Reference in New Issue
Block a user