diff options
author | Araq <rumpf_a@web.de> | 2015-10-22 10:24:46 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-10-22 10:24:46 +0200 |
commit | d93507fd2e88fe1cffb69b8f0cf50a6670bfbecc (patch) | |
tree | 89faafcf65bc98173089db45865dc971ddb2fc19 /compiler | |
parent | 3f24a7ff3ea45253b496ab08c2bdecb838f0419d (diff) | |
download | Nim-d93507fd2e88fe1cffb69b8f0cf50a6670bfbecc.tar.gz |
fixes #3338
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/seminst.nim | 8 | ||||
-rw-r--r-- | compiler/semtypinst.nim | 8 | ||||
-rw-r--r-- | compiler/types.nim | 4 |
3 files changed, 16 insertions, 4 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim index abc5600c3..f9a137740 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -239,14 +239,20 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, pushInfoContext(info) var entry = TInstantiation.new entry.sym = result - newSeq(entry.concreteTypes, gp.len) + # we need to compare both the generic types and the concrete types: + # generic[void](), generic[int]() + # see ttypeor.nim test. var i = 0 + newSeq(entry.concreteTypes, fn.typ.len+gp.len) for s in instantiateGenericParamList(c, gp, pt): addDecl(c, s) entry.concreteTypes[i] = s.typ inc i pushProcCon(c, result) instantiateProcType(c, pt, result, info) + for j in 0 .. result.typ.len-1: + entry.concreteTypes[i] = result.typ.sons[j] + inc i if tfTriggersCompileTime in result.typ.flags: incl(result.flags, sfCompileTime) n.sons[genericParamsPos] = ast.emptyNode diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index f643fb903..7957ac50a 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -75,8 +75,12 @@ proc searchInstTypes*(key: PType): PType = proc cacheTypeInst*(inst: PType) = # XXX: add to module's generics # update the refcount - let genericTyp = inst.sons[0] - genericTyp.sym.typeInstCache.safeAdd(inst) + let gt = inst.sons[0] + let t = if gt.kind == tyGenericBody: gt.lastSon else: gt + if t.kind in {tyStatic, tyGenericParam, tyIter} + tyTypeClasses: + return + gt.sym.typeInstCache.safeAdd(inst) + type TReplTypeVars* {.final.} = object diff --git a/compiler/types.nim b/compiler/types.nim index 66fb657fc..3846be8a0 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -991,7 +991,9 @@ proc compareTypes*(x, y: PType, var c = initSameTypeClosure() c.cmp = cmp c.flags = flags - result = sameTypeAux(x, y, c) + if x == y: result = true + elif x.isNil or y.isNil: result = false + else: result = sameTypeAux(x, y, c) proc inheritanceDiff*(a, b: PType): int = # | returns: 0 iff `a` == `b` |