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