fixes #5417
This commit is contained in:
parent
22789a0bfc
commit
2d546ca0ac
5 changed files with 28 additions and 7 deletions
|
|
@ -540,7 +540,7 @@ proc genBreakStmt(p: BProc, t: PNode) =
|
||||||
# named break?
|
# named break?
|
||||||
assert(t.sons[0].kind == nkSym)
|
assert(t.sons[0].kind == nkSym)
|
||||||
var sym = t.sons[0].sym
|
var sym = t.sons[0].sym
|
||||||
assert(sym.loc.k == locOther)
|
doAssert(sym.loc.k == locOther)
|
||||||
idx = sym.position-1
|
idx = sym.position-1
|
||||||
else:
|
else:
|
||||||
# an unnamed 'break' can only break a loop after 'transf' pass:
|
# 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)
|
var labl = newSymG(skLabel, n.sons[0], c)
|
||||||
if sfGenSym notin labl.flags:
|
if sfGenSym notin labl.flags:
|
||||||
addDecl(c, labl)
|
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)
|
suggestSym(n.sons[0].info, labl)
|
||||||
styleCheckDef(labl)
|
styleCheckDef(labl)
|
||||||
n.sons[1] = semExpr(c, n.sons[1])
|
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 nkIdent: s = lookUp(c, n.sons[0])
|
||||||
of nkSym: s = n.sons[0].sym
|
of nkSym: s = n.sons[0].sym
|
||||||
else: illFormedAst(n)
|
else: illFormedAst(n)
|
||||||
|
s = getGenSym(c, s)
|
||||||
if s.kind == skLabel and s.owner.id == c.p.owner.id:
|
if s.kind == skLabel and s.owner.id == c.p.owner.id:
|
||||||
var x = newSymNode(s)
|
var x = newSymNode(s)
|
||||||
x.info = n.info
|
x.info = n.info
|
||||||
|
|
|
||||||
|
|
@ -384,11 +384,13 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
openScope(c)
|
openScope(c)
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
# labels are always 'gensym'ed:
|
addLocalDecl(c, n.sons[0], skLabel)
|
||||||
let s = newGenSym(skLabel, n.sons[0], c)
|
when false:
|
||||||
addPrelimDecl(c.c, s)
|
# labels are always 'gensym'ed:
|
||||||
styleCheckDef(s)
|
let s = newGenSym(skLabel, n.sons[0], c)
|
||||||
n.sons[0] = newSymNode(s, n.sons[0].info)
|
addPrelimDecl(c.c, s)
|
||||||
|
styleCheckDef(s)
|
||||||
|
n.sons[0] = newSymNode(s, n.sons[0].info)
|
||||||
n.sons[1] = semTemplBody(c, n.sons[1])
|
n.sons[1] = semTemplBody(c, n.sons[1])
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
of nkTryStmt:
|
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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue