diff options
Diffstat (limited to 'compiler/semtypinst.nim')
-rw-r--r-- | compiler/semtypinst.nim | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 5d2c4203c..e5a51b50d 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -63,11 +63,10 @@ proc cacheTypeInst*(inst: PType) = # update the refcount let gt = inst.sons[0] let t = if gt.kind == tyGenericBody: gt.lastSon else: gt - if t.kind in {tyStatic, tyGenericParam} + tyTypeClasses: + if t.kind in {tyStatic, tyError, tyGenericParam} + tyTypeClasses: return gt.sym.typeInstCache.add(inst) - type LayeredIdTable* = object topLayer*: TIdTable @@ -170,7 +169,7 @@ proc replaceObjBranches(cl: TReplTypeVars, n: PNode): PNode = discard of nkRecWhen: var branch: PNode = nil # the branch to take - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): var it = n.sons[i] if it == nil: illFormedAst(n, cl.c.config) case it.kind @@ -209,7 +208,7 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0): PNode = result = newNode(nkRecList, n.info) of nkRecWhen: var branch: PNode = nil # the branch to take - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): var it = n.sons[i] if it == nil: illFormedAst(n, cl.c.config) case it.kind @@ -239,7 +238,7 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0): PNode = newSons(result, length) if start > 0: result.sons[0] = n.sons[0] - for i in countup(start, length - 1): + for i in start ..< length: result.sons[i] = replaceTypeVarsN(cl, n.sons[i]) proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym = @@ -311,7 +310,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType = when defined(reportCacheHits): echo "Generic instantiation cached ", typeToString(result), " for ", typeToString(t) return - for i in countup(1, sonsLen(t) - 1): + for i in 1 ..< sonsLen(t): var x = t.sons[i] if x.kind in {tyGenericParam}: x = lookupTypeVar(cl, x) @@ -351,18 +350,21 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType = var typeMapLayer = newTypeMapLayer(cl) cl.typeMap = addr(typeMapLayer) - for i in countup(1, sonsLen(t) - 1): + for i in 1 ..< sonsLen(t): var x = replaceTypeVarsT(cl, t.sons[i]) assert x.kind != tyGenericInvocation header.sons[i] = x propagateToOwner(header, x) cl.typeMap.put(body.sons[i-1], x) - for i in countup(1, sonsLen(t) - 1): + for i in 1 ..< sonsLen(t): # if one of the params is not concrete, we cannot do anything # but we already raised an error! rawAddSon(result, header.sons[i]) + if body.kind == tyError: + return + let bbody = lastSon body var newbody = replaceTypeVarsT(cl, bbody) let bodyIsNew = newbody != bbody @@ -560,7 +562,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = #if not cl.allowMetaTypes: idTablePut(cl.localCache, t, result) - for i in countup(0, sonsLen(result) - 1): + for i in 0 ..< sonsLen(result): if result.sons[i] != nil: if result.sons[i].kind == tyGenericBody: localError(cl.c.config, t.sym.info, |