This commit is contained in:
Andreas Rumpf 2017-02-24 00:32:03 +01:00
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? # 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:

View file

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

View file

@ -384,6 +384,8 @@ 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:
addLocalDecl(c, n.sons[0], skLabel)
when false:
# labels are always 'gensym'ed: # labels are always 'gensym'ed:
let s = newGenSym(skLabel, n.sons[0], c) let s = newGenSym(skLabel, n.sons[0], c)
addPrelimDecl(c.c, s) addPrelimDecl(c.c, s)

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