diff options
Diffstat (limited to 'compiler/semtypinst.nim')
-rw-r--r-- | compiler/semtypinst.nim | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 3ac145eb8..f643fb903 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -90,6 +90,7 @@ type allowMetaTypes*: bool # allow types such as seq[Number] # i.e. the result contains unresolved generics skipTypedesc*: bool # wether we should skip typeDescs + owner*: PSym # where this instantiation comes from recursionLimit: int proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType @@ -208,6 +209,9 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode): PNode = proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym = if s == nil: return nil + # symbol is not our business: + if cl.owner != nil and s.owner != cl.owner: + return s result = PSym(idTableGet(cl.symMap, s)) if result == nil: result = copySym(s, false) @@ -477,22 +481,33 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = else: discard -proc initTypeVars*(p: PContext, pt: TIdTable, info: TLineInfo): TReplTypeVars = +proc initTypeVars*(p: PContext, pt: TIdTable, info: TLineInfo; + owner: PSym): TReplTypeVars = initIdTable(result.symMap) copyIdTable(result.typeMap, pt) initIdTable(result.localCache) result.info = info result.c = p + result.owner = owner -proc replaceTypesInBody*(p: PContext, pt: TIdTable, n: PNode): PNode = - var cl = initTypeVars(p, pt, n.info) +proc replaceTypesInBody*(p: PContext, pt: TIdTable, n: PNode; + owner: PSym): PNode = + var cl = initTypeVars(p, pt, n.info, owner) + pushInfoContext(n.info) + result = replaceTypeVarsN(cl, n) + popInfoContext() + +proc replaceTypesForLambda*(p: PContext, pt: TIdTable, n: PNode; + original, new: PSym): PNode = + var cl = initTypeVars(p, pt, n.info, original) + idTablePut(cl.symMap, original, new) pushInfoContext(n.info) result = replaceTypeVarsN(cl, n) popInfoContext() proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo, t: PType): PType = - var cl = initTypeVars(p, pt, info) + var cl = initTypeVars(p, pt, info, nil) pushInfoContext(info) result = replaceTypeVarsT(cl, t) popInfoContext() |