From b7f11b8b0ad9fb7bb71b71a17d3372e3269e5599 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 18 Feb 2015 13:22:06 +0100 Subject: fixes #2125 --- compiler/ast.nim | 6 ++++++ compiler/seminst.nim | 26 ++++++++++++++++++-------- compiler/semtypinst.nim | 2 +- compiler/sigmatch.nim | 20 ++++++++++++++------ 4 files changed, 39 insertions(+), 15 deletions(-) (limited to 'compiler') 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 .. 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: -- cgit 1.4.1-2-gfad0 #n43'>43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136