@@ -4463,34 +4463,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
4463
4463
auto meta1 = cast<AnyMetatypeType>(desugar1);
4464
4464
auto meta2 = cast<AnyMetatypeType>(desugar2);
4465
4465
4466
- auto instanceType1 = meta1->getInstanceType ();
4467
- auto instanceType2 = meta2->getInstanceType ();
4468
-
4469
4466
// A.Type < B.Type if A < B and both A and B are classes.
4470
4467
// P.Type < Q.Type if P < Q, both P and Q are protocols, and P.Type
4471
- // and Q.Type are both existential metatypes.
4472
- auto getSubKind = [&]() -> ConstraintKind {
4473
- auto subKind = std::min (kind, ConstraintKind::Subtype);
4474
-
4475
- // If we have existential metatypes, we need to perform subtyping.
4476
- if (!isa<MetatypeType>(meta1))
4477
- return subKind;
4478
-
4479
- // If the LHS cannot be a type with a superclass, we can perform a bind.
4480
- if (!instanceType1->isTypeVariableOrMember () &&
4481
- !instanceType1->mayHaveSuperclass ())
4482
- return ConstraintKind::Bind;
4483
-
4484
- // If the RHS cannot be a class type, we can perform a bind.
4485
- if (!instanceType2->isTypeVariableOrMember () &&
4486
- !instanceType2->getClassOrBoundGenericClass ())
4487
- return ConstraintKind::Bind;
4488
-
4489
- return subKind;
4490
- };
4468
+ // and Q.Type are both existential metatypes
4469
+ auto subKind = std::min (kind, ConstraintKind::Subtype);
4470
+ // If instance types can't have a subtype relationship
4471
+ // it means that such types can be simply equated.
4472
+ auto instanceType1 = meta1->getInstanceType ();
4473
+ auto instanceType2 = meta2->getInstanceType ();
4474
+ if (isa<MetatypeType>(meta1) &&
4475
+ !(instanceType1->mayHaveSuperclass () &&
4476
+ instanceType2->getClassOrBoundGenericClass ())) {
4477
+ subKind = ConstraintKind::Bind;
4478
+ }
4491
4479
4492
4480
auto result =
4493
- matchTypes (instanceType1, instanceType2, getSubKind () , subflags,
4481
+ matchTypes (instanceType1, instanceType2, subKind , subflags,
4494
4482
locator.withPathElement (ConstraintLocator::InstanceType));
4495
4483
4496
4484
// If matching of the instance types resulted in the failure make sure
0 commit comments