This commit is contained in:
Andreas Rumpf
2017-02-24 00:32:03 +01:00
parent 22789a0bfc
commit 2d546ca0ac
5 changed files with 28 additions and 7 deletions

View File

@@ -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:

View File

@@ -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])

View File

@@ -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

View File

@@ -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:

View 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()