summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-02-18 13:22:06 +0100
committerAraq <rumpf_a@web.de>2015-02-18 13:44:01 +0100
commitb7f11b8b0ad9fb7bb71b71a17d3372e3269e5599 (patch)
treed116a126dea728c7f3556156fb2d9cdf2bd216e9 /compiler
parente6dcceae6cb2a00ec9bdc0cb63ab44956dc98093 (diff)
downloadNim-b7f11b8b0ad9fb7bb71b71a17d3372e3269e5599.tar.gz
fixes #2125
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ast.nim6
-rw-r--r--compiler/seminst.nim26
-rw-r--r--compiler/semtypinst.nim2
-rw-r--r--compiler/sigmatch.nim20
4 files changed, 39 insertions, 15 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 18b6e6b37..b327218a1 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -1298,6 +1298,12 @@ proc initIdTable(x: var TIdTable) =
   x.counter = 0
   newSeq(x.data, StartSize)
 
+proc resetIdTable*(x: var TIdTable) =
+  x.counter = 0
+  # clear and set to old initial size:
+  setLen(x.data, 0)
+  setLen(x.data, StartSize)
+
 proc initObjectSet(x: var TObjectSet) = 
   x.counter = 0
   newSeq(x.data, StartSize)
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index 3d2427a89..d74584096 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -174,17 +174,27 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
   result.n = originalParams.shallowCopy
   
   for i in 1 .. <result.len:
+    # twrong_field_caching requires these 'resetIdTable' calls:
+    if i > 1: resetIdTable(cl.symMap)
     result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
     propagateToOwner(result, result.sons[i])
-    let param = replaceTypeVarsN(cl, originalParams[i])
-    result.n.sons[i] = param
-    if param.kind == nkSym:
-      # XXX: this won't be true for void params
-      # implement pass-through of void params and
-      # the "sort by distance to point" container
+    internalAssert originalParams[i].kind == nkSym
+    when true:
+      let oldParam = originalParams[i].sym
+      let param = copySym(oldParam)
+      param.owner = prc
+      param.typ = result.sons[i]
+      param.ast = oldParam.ast.copyTree
+      # don't be lazy here and call replaceTypeVarsN(cl, originalParams[i])!
+      result.n.sons[i] = newSymNode(param)
+      addDecl(c, param)
+    else:
+      let param = replaceTypeVarsN(cl, originalParams[i])
+      result.n.sons[i] = param
       param.sym.owner = prc
-      addDecl(c, param.sym)
-    
+      addDecl(c, result.n.sons[i].sym)
+
+  resetIdTable(cl.symMap)
   result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
   result.n.sons[0] = originalParams[0].copyTree
   
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 9688520f3..12fce1b84 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -223,7 +223,7 @@ proc lookupTypeVar(cl: var TReplTypeVars, t: PType): PType =
     result = errorType(cl.c)
     # In order to prevent endless recursions, we must remember
     # this bad lookup and replace it with errorType everywhere.
-    # These code paths are only active in nimrod check
+    # These code paths are only active in "nim check"
     idTablePut(cl.typeMap, t, result)
   elif result.kind == tyGenericParam and not cl.allowMetaTypes:
     internalError(cl.info, "substitution with generic parameter")
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index e6e43d78c..a782658b6 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1261,12 +1261,20 @@ proc paramTypesMatchAux(m: var TCandidate, f, argType: PType,
       result = implicitConv(nkHiddenStdConv, f, result, m, c)
   of isGeneric:
     inc(m.genericMatches)
-    result = copyTree(arg)
-    result.typ = getInstantiatedType(c, arg, m, f)
-    # BUG: f may not be the right key!
-    if skipTypes(result.typ, abstractVar-{tyTypeDesc}).kind in {tyTuple}:
-      result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
-      # BUGFIX: use ``result.typ`` and not `f` here
+    when false:
+      if skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple:
+        result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
+      else:
+        result = arg.copyTree
+    else:
+      # XXX Why is this ever necessary? arg's type should not be retrofitted
+      # to match formal's type in this way!
+      result = copyTree(arg)
+      result.typ = getInstantiatedType(c, arg, m, f)
+      # BUG: f may not be the right key!
+      if skipTypes(result.typ, abstractVar-{tyTypeDesc}).kind in {tyTuple}:
+        result = implicitConv(nkHiddenStdConv, f, copyTree(arg), m, c)
+        # BUGFIX: use ``result.typ`` and not `f` here
   of isFromIntLit:
     # too lazy to introduce another ``*matches`` field, so we conflate
     # ``isIntConv`` and ``isIntLit`` here: