diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-12-28 15:01:40 +0200 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-12-28 15:07:30 +0200 |
commit | 5d75ce2f2eec8d4ec6f152105a144abcf73e4a37 (patch) | |
tree | 60a3500b547620832b5b863bfc3ac7ae3ec237d2 /compiler | |
parent | f34ca1a7d7fe22c762b1a4bc29f4f1e19d5da0ec (diff) | |
download | Nim-5d75ce2f2eec8d4ec6f152105a144abcf73e4a37.tar.gz |
fix tclosure4
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semtypes.nim | 1 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 17 |
2 files changed, 12 insertions, 6 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 6f6d0c4c5..1251a25c0 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -673,6 +673,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true)) result = instGenericContainer(c, paramType.sym.info, result, allowMetaTypes = true) + result.lastSon.flags.incl tfHasMeta result = newTypeWithSons(c, tyCompositeTypeClass, @[paramType, result]) result = addImplicitGeneric(result) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 18020b95c..43ca6e666 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -303,21 +303,23 @@ proc minRel(a, b: TTypeRelation): TTypeRelation = if a <= b: result = a else: result = b -proc tupleRel(c: var TCandidate, f, a: PType): TTypeRelation = +proc recordRel(c: var TCandidate, f, a: PType): TTypeRelation = result = isNone if sameType(f, a): result = isEqual elif sonsLen(a) == sonsLen(f): result = isEqual - for i in countup(0, sonsLen(f) - 1): + let firstField = if f.kind == tyTuple: 0 + else: 1 + for i in countup(firstField, sonsLen(f) - 1): var m = typeRel(c, f.sons[i], a.sons[i]) if m < isSubtype: return isNone result = minRel(result, m) if f.n != nil and a.n != nil: for i in countup(0, sonsLen(f.n) - 1): # check field names: - if f.n.sons[i].kind != nkSym: InternalError(f.n.info, "tupleRel") - elif a.n.sons[i].kind != nkSym: InternalError(a.n.info, "tupleRel") + if f.n.sons[i].kind != nkSym: InternalError(f.n.info, "recordRel") + elif a.n.sons[i].kind != nkSym: InternalError(a.n.info, "recordRel") else: var x = f.n.sons[i].sym var y = a.n.sons[i].sym @@ -408,11 +410,13 @@ proc typeRel(c: var TCandidate, f, a: PType, doBind = true): TTypeRelation = result = isNone assert(f != nil) assert(a != nil) + if a.kind == tyGenericInst and skipTypes(f, {tyVar}).kind notin { tyGenericBody, tyGenericInvokation, - tyGenericParam, tyTypeClass}: + tyGenericParam} + tyTypeClasses: return typeRel(c, f, lastSon(a)) + if a.kind == tyVar and f.kind != tyVar: return typeRel(c, f, a.sons[0]) @@ -559,10 +563,11 @@ proc typeRel(c: var TCandidate, f, a: PType, doBind = true): TTypeRelation = of tyNil: if a.kind == f.kind: result = isEqual of tyTuple: - if a.kind == tyTuple: result = tupleRel(c, f, a) + if a.kind == tyTuple: result = recordRel(c, f, a) of tyObject: if a.kind == tyObject: if sameObjectTypes(f, a): result = isEqual + elif tfHasMeta in f.flags: result = recordRel(c, f, a) else: var depth = isObjectSubtype(a, f) if depth > 0: |