diff options
author | Araq <rumpf_a@web.de> | 2015-02-25 20:32:32 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-02-25 20:32:32 +0100 |
commit | f2cdbc92eb2aead4b7ee4c8a9156e17edc2edd9c (patch) | |
tree | 19078b59858822cc063920b9169492456b151b2b /compiler | |
parent | 335c19c8692086ddb845af1b840b49e306c5179b (diff) | |
download | Nim-f2cdbc92eb2aead4b7ee4c8a9156e17edc2edd9c.tar.gz |
fixes #2215
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/seminst.nim | 21 | ||||
-rw-r--r-- | compiler/semtempl.nim | 2 |
2 files changed, 12 insertions, 11 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim index d74584096..a10f27519 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -80,13 +80,9 @@ proc freshGenSyms(n: PNode, owner: PSym, symMap: var TIdTable) = let s = n.sym var x = PSym(idTableGet(symMap, s)) if x == nil: - if s.kind == skParam: - x = owner.typ.n[s.position+1].sym - internalAssert x.kind == skParam - else: - x = copySym(s, false) - x.owner = owner - idTablePut(symMap, s, x) + x = copySym(s, false) + x.owner = owner + idTablePut(symMap, s, x) n.sym = x else: for i in 0 .. <safeLen(n): freshGenSyms(n.sons[i], owner, symMap) @@ -104,13 +100,18 @@ proc addProcDecls(c: PContext, fn: PSym) = maybeAddResult(c, fn, fn.ast) -proc instantiateBody(c: PContext, n: PNode, result: PSym) = +proc instantiateBody(c: PContext, n, params: PNode, result: PSym) = if n.sons[bodyPos].kind != nkEmpty: inc c.inGenericInst # add it here, so that recursive generic procs are possible: var b = n.sons[bodyPos] var symMap: TIdTable initIdTable symMap + if params != nil: + for i in 1 .. <params.len: + let param = params[i].sym + if sfGenSym in param.flags: + idTablePut(symMap, params[i].sym, result.typ.n[param.position+1].sym) freshGenSyms(b, result, symMap) b = semProcBody(c, b) b = hloBody(c, b) @@ -127,7 +128,7 @@ proc fixupInstantiatedSymbols(c: PContext, s: PSym) = openScope(c) var n = oldPrc.ast n.sons[bodyPos] = copyTree(s.getBody) - instantiateBody(c, n, oldPrc) + instantiateBody(c, n, nil, oldPrc) closeScope(c) popInfoContext() @@ -249,7 +250,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, pragma(c, result, n.sons[pragmasPos], allRoutinePragmas) if isNil(n.sons[bodyPos]): n.sons[bodyPos] = copyTree(fn.getBody) - instantiateBody(c, n, result) + instantiateBody(c, n, fn.typ.n, result) sideEffectsCheck(c, result) paramsTypeCheck(c, result.typ) else: diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 47602368a..a48f045a2 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -494,7 +494,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = semParamList(c, n.sons[paramsPos], gp, s) # a template's parameters are not gensym'ed even if that was originally the # case as we determine whether it's a template parameter in the template - # body by the absence of the skGenSym flag: + # body by the absence of the sfGenSym flag: for i in 1 .. s.typ.n.len-1: s.typ.n.sons[i].sym.flags.excl sfGenSym if sonsLen(gp) > 0: |