@@ -4394,34 +4394,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
4394
4394
auto meta1 = cast<AnyMetatypeType>(desugar1);
4395
4395
auto meta2 = cast<AnyMetatypeType>(desugar2);
4396
4396
4397
- auto instanceType1 = meta1->getInstanceType ();
4398
- auto instanceType2 = meta2->getInstanceType ();
4399
-
4400
4397
// A.Type < B.Type if A < B and both A and B are classes.
4401
4398
// P.Type < Q.Type if P < Q, both P and Q are protocols, and P.Type
4402
- // and Q.Type are both existential metatypes.
4403
- auto getSubKind = [&]() -> ConstraintKind {
4404
- auto subKind = std::min (kind, ConstraintKind::Subtype);
4405
-
4406
- // If we have existential metatypes, we need to perform subtyping.
4407
- if (!isa<MetatypeType>(meta1))
4408
- return subKind;
4409
-
4410
- // If the LHS cannot be a type with a superclass, we can perform a bind.
4411
- if (!instanceType1->isTypeVariableOrMember () &&
4412
- !instanceType1->mayHaveSuperclass ())
4413
- return ConstraintKind::Bind;
4414
-
4415
- // If the RHS cannot be a class type, we can perform a bind.
4416
- if (!instanceType2->isTypeVariableOrMember () &&
4417
- !instanceType2->getClassOrBoundGenericClass ())
4418
- return ConstraintKind::Bind;
4419
-
4420
- return subKind;
4421
- };
4399
+ // and Q.Type are both existential metatypes
4400
+ auto subKind = std::min (kind, ConstraintKind::Subtype);
4401
+ // If instance types can't have a subtype relationship
4402
+ // it means that such types can be simply equated.
4403
+ auto instanceType1 = meta1->getInstanceType ();
4404
+ auto instanceType2 = meta2->getInstanceType ();
4405
+ if (isa<MetatypeType>(meta1) &&
4406
+ !(instanceType1->mayHaveSuperclass () &&
4407
+ instanceType2->getClassOrBoundGenericClass ())) {
4408
+ subKind = ConstraintKind::Bind;
4409
+ }
4422
4410
4423
4411
auto result =
4424
- matchTypes (instanceType1, instanceType2, getSubKind () , subflags,
4412
+ matchTypes (instanceType1, instanceType2, subKind , subflags,
4425
4413
locator.withPathElement (ConstraintLocator::InstanceType));
4426
4414
4427
4415
// If matching of the instance types resulted in the failure make sure
0 commit comments