@@ -1969,21 +1969,23 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1969
1969
auto meta1 = cast<AnyMetatypeType>(desugar1);
1970
1970
auto meta2 = cast<AnyMetatypeType>(desugar2);
1971
1971
1972
- ConstraintKind subKind = ConstraintKind::Equal;
1973
1972
// A.Type < B.Type if A < B and both A and B are classes.
1974
- if (isa<MetatypeType>(meta1) &&
1975
- meta1->getInstanceType ()->mayHaveSuperclass () &&
1976
- meta2->getInstanceType ()->getClassOrBoundGenericClass ())
1977
- subKind = std::min (kind, ConstraintKind::Subtype);
1978
1973
// P.Type < Q.Type if P < Q, both P and Q are protocols, and P.Type
1979
- // and Q.Type are both existential metatypes.
1980
- else if (isa<ExistentialMetatypeType>(meta1))
1981
- subKind = std::min (kind, ConstraintKind::Subtype);
1982
-
1983
- return matchTypes (meta1->getInstanceType (), meta2->getInstanceType (),
1984
- subKind, subflags,
1985
- locator.withPathElement (
1986
- ConstraintLocator::InstanceType));
1974
+ // and Q.Type are both existential metatypes
1975
+ auto subKind = std::min (kind, ConstraintKind::Subtype);
1976
+ // If instance types can't have a subtype relationship
1977
+ // it means that such types can be simply equated.
1978
+ auto instanceType1 = meta1->getInstanceType ();
1979
+ auto instanceType2 = meta2->getInstanceType ();
1980
+ if (isa<MetatypeType>(meta1) &&
1981
+ !(instanceType1->mayHaveSuperclass () &&
1982
+ instanceType2->getClassOrBoundGenericClass ())) {
1983
+ subKind = ConstraintKind::Equal;
1984
+ }
1985
+
1986
+ return matchTypes (
1987
+ instanceType1, instanceType2, subKind, subflags,
1988
+ locator.withPathElement (ConstraintLocator::InstanceType));
1987
1989
}
1988
1990
1989
1991
case TypeKind::Function: {
0 commit comments