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