diff options
Diffstat (limited to 'compiler/evaltempl.nim')
-rw-r--r-- | compiler/evaltempl.nim | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim index 2a01a7911..c1024e2fe 100644 --- a/compiler/evaltempl.nim +++ b/compiler/evaltempl.nim @@ -21,6 +21,7 @@ type # new symbol config: ConfigRef ic: IdentCache + instID: int proc copyNode(ctx: TemplCtx, a, b: PNode): PNode = result = copyNode(a) @@ -53,8 +54,8 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) = #if x.kind == skParam and x.owner.kind == skModule: # internalAssert c.config, false idTablePut(c.mapping, s, x) - if sfGenSym in s.flags and optNimV019 notin c.config.globalOptions: - result.add newIdentNode(getIdent(c.ic, x.name.s & "`gensym" & $x.id), + if sfGenSym in s.flags: + result.add newIdentNode(getIdent(c.ic, x.name.s & "`gensym" & $c.instID), if c.instLines: actual.info else: templ.info) else: result.add newSymNode(x, if c.instLines: actual.info else: templ.info) @@ -166,7 +167,7 @@ proc wrapInComesFrom*(info: TLineInfo; sym: PSym; res: PNode): PNode = proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; conf: ConfigRef; - ic: IdentCache; + ic: IdentCache; instID: ref int; fromHlo=false): PNode = inc(conf.evalTemplateCounter) if conf.evalTemplateCounter > evalTemplateLimit: @@ -181,6 +182,7 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; ctx.config = conf ctx.ic = ic initIdTable(ctx.mapping) + ctx.instID = instID[] let body = tmpl.getBody #echo "instantion of ", renderTree(body, {renderIds}) @@ -203,3 +205,5 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; #if ctx.debugActive: # echo "instantion of ", renderTree(result, {renderIds}) dec(conf.evalTemplateCounter) + # The instID must be unique for every template instantiation, so we increment it here + inc instID[] |