diff options
-rw-r--r-- | compiler/ccgstmts.nim | 2 | ||||
-rw-r--r-- | compiler/semexprs.nim | 2 | ||||
-rw-r--r-- | compiler/semstmts.nim | 1 | ||||
-rw-r--r-- | compiler/semtempl.nim | 12 | ||||
-rw-r--r-- | tests/template/tgensym_label.nim | 18 |
5 files changed, 28 insertions, 7 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index e4f13c70b..3a861ebd4 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -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: diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 542d7b4e3..d9a5f6c50 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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]) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index e2b0f4b7a..282d4da88 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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 diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 8819f17cc..420e36116 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -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: diff --git a/tests/template/tgensym_label.nim b/tests/template/tgensym_label.nim new file mode 100644 index 000000000..fd3b0a1ee --- /dev/null +++ b/tests/template/tgensym_label.nim @@ -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() |