summary refs log tree commit diff stats
path: root/compiler/seminst.nim
diff options
context:
space:
mode:
authorzah <zahary@gmail.com>2017-03-23 13:40:57 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-03-23 12:40:57 +0100
commitbe174fc3c731f1aecf07d7750c038dbb7a018812 (patch)
tree28d5c29b1043e0eab56b5d99286e9b5e73b2c572 /compiler/seminst.nim
parent70237e1fdd966c06f7ef4a4211456c27c4d644e7 (diff)
downloadNim-be174fc3c731f1aecf07d7750c038dbb7a018812.tar.gz
Fix generic forward declarations; fixes #4104; fixes #4908 (#5566)
Diffstat (limited to 'compiler/seminst.nim')
-rw-r--r--compiler/seminst.nim14
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index 78dd7efe5..71752f5c3 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -125,6 +125,11 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind)
 
 proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) =
   if n.sons[bodyPos].kind != nkEmpty:
+    let procParams = result.typ.n
+    for i in 1 .. <procParams.len:
+      addDecl(c, procParams[i].sym)
+    maybeAddResult(c, result, result.ast)
+
     inc c.inGenericInst
     # add it here, so that recursive generic procs are possible:
     var b = n.sons[bodyPos]
@@ -147,13 +152,17 @@ proc fixupInstantiatedSymbols(c: PContext, s: PSym) =
   for i in countup(0, c.generics.len - 1):
     if c.generics[i].genericSym.id == s.id:
       var oldPrc = c.generics[i].inst.sym
+      pushProcCon(c, oldPrc)
+      pushOwner(c, oldPrc)
       pushInfoContext(oldPrc.info)
       openScope(c)
       var n = oldPrc.ast
       n.sons[bodyPos] = copyTree(s.getBody)
-      instantiateBody(c, n, nil, oldPrc, s)
+      instantiateBody(c, n, oldPrc.typ.n, oldPrc, s)
       closeScope(c)
       popInfoContext()
+      popOwner(c)
+      popProcCon(c)
 
 proc sideEffectsCheck(c: PContext, s: PSym) =
   when false:
@@ -173,7 +182,7 @@ proc instGenericContainer(c: PContext, info: TLineInfo, header: PType,
   result = replaceTypeVarsT(cl, header)
 
 proc instantiateProcType(c: PContext, pt: TIdTable,
-                          prc: PSym, info: TLineInfo) =
+                         prc: PSym, info: TLineInfo) =
   # XXX: Instantiates a generic proc signature, while at the same
   # time adding the instantiated proc params into the current scope.
   # This is necessary, because the instantiation process may refer to
@@ -229,7 +238,6 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
   skipIntLiteralParams(result)
 
   prc.typ = result
-  maybeAddResult(c, prc, prc.ast)
   popInfoContext()
 
 proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,