From ec4985a5733c9e65e162ece35dca90b37b193f1c Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 18 Oct 2018 16:53:49 +0200 Subject: [PATCH] fixes #7972 --- compiler/transf.nim | 23 +++++++++++++---------- tests/trmacros/tstmtlist.nim | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/compiler/transf.nim b/compiler/transf.nim index 6b6335129..473c9f2bd 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -199,17 +199,20 @@ proc transformVarSection(c: PTransf, v: PNode): PTransNode = result[i] = defs proc transformConstSection(c: PTransf, v: PNode): PTransNode = - result = newTransNode(v) - for i in countup(0, sonsLen(v)-1): - var it = v.sons[i] - if it.kind == nkCommentStmt: - result[i] = PTransNode(it) - else: - if it.kind != nkConstDef: internalError(c.graph.config, it.info, "transformConstSection") - if it.sons[0].kind != nkSym: - internalError(c.graph.config, it.info, "transformConstSection") + result = PTransNode(v) + when false: + result = newTransNode(v) + for i in countup(0, sonsLen(v)-1): + var it = v.sons[i] + if it.kind == nkCommentStmt: + result[i] = PTransNode(it) + else: + if it.kind != nkConstDef: internalError(c.graph.config, it.info, "transformConstSection") + if it.sons[0].kind != nkSym: + debug it.sons[0] + internalError(c.graph.config, it.info, "transformConstSection") - result[i] = PTransNode(it) + result[i] = PTransNode(it) proc hasContinue(n: PNode): bool = case n.kind diff --git a/tests/trmacros/tstmtlist.nim b/tests/trmacros/tstmtlist.nim index 751acb79a..8261e7c45 100644 --- a/tests/trmacros/tstmtlist.nim +++ b/tests/trmacros/tstmtlist.nim @@ -17,3 +17,18 @@ if true: writeLine stdout, "2" write stdout, "3" echo "4" + +# bug #7972 + +template optimizeLogWrites*{ + write(f, x) + write(f, y) +}(x, y: string{lit}, f: File) = + write(f, x & y) + +proc foo() = + const N = 1 + stdout.write("") + stdout.write("") + +foo()