@@ -257,31 +257,31 @@ proc tupleRel(c: var TCandidate, f, a: PType): TTypeRelation =
257257 var y = a.n.sons[i].sym
258258 if x.name.id != y.name.id: return isNone
259259
260- proc matchTypeClass (c: var TCandidate , f, a : PType ): TTypeRelation =
261- for i in countup (0 , f .sonsLen - 1 ):
262- let son = f .sons[i]
263- var match = son .kind == skipTypes (a , {tyRange, tyGenericInst}).kind
264-
260+ proc matchTypeClass (c: var TCandidate , typeClass, t : PType ): TTypeRelation =
261+ for i in countup (0 , typeClass .sonsLen - 1 ):
262+ let req = typeClass .sons[i]
263+ var match = req .kind == skipTypes (t , {tyRange, tyGenericInst}).kind
264+
265265 if not match:
266- case son .kind
266+ case req .kind
267267 of tyGenericBody:
268- if a .kind == tyGenericInst and a .sons[0 ] == son :
268+ if t .kind == tyGenericInst and t .sons[0 ] == req :
269269 match = true
270- put (c.bindings, f, a )
270+ put (c.bindings, typeClass, t )
271271 of tyTypeClass:
272- match = matchTypeClass (c, son, a ) == isGeneric
272+ match = matchTypeClass (c, req, t ) == isGeneric
273273 else : nil
274+ elif t.kind in {tyTypeDesc, tyObject}:
275+ match = sameType (t, req)
274276
275- if tfAny in f.flags:
276- if match:
277- return isGeneric
277+ if tfAny in typeClass.flags:
278+ if match: return isGeneric
278279 else :
279- if not match:
280- return isNone
280+ if not match: return isNone
281281
282282 # if the loop finished without returning, either all constraints matched
283283 # or none of them matched.
284- result = if tfAny in f .flags: isNone else : isGeneric
284+ result = if tfAny in typeClass .flags: isNone else : isGeneric
285285
286286proc procTypeRel (c: var TCandidate , f, a: PType ): TTypeRelation =
287287 proc inconsistentVarTypes (f, a: PType ): bool {.inline .} =
0 commit comments