Skip to content

Commit 191fcc4

Browse files
committed
Revert "[CS] Account for type variables when matching metatypes"
This reverts commit 84a3db4.
1 parent 11b9586 commit 191fcc4

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,34 +4392,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
43924392
auto meta1 = cast<AnyMetatypeType>(desugar1);
43934393
auto meta2 = cast<AnyMetatypeType>(desugar2);
43944394

4395-
auto instanceType1 = meta1->getInstanceType();
4396-
auto instanceType2 = meta2->getInstanceType();
4397-
43984395
// A.Type < B.Type if A < B and both A and B are classes.
43994396
// 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+
}
44204408

44214409
auto result =
4422-
matchTypes(instanceType1, instanceType2, getSubKind(), subflags,
4410+
matchTypes(instanceType1, instanceType2, subKind, subflags,
44234411
locator.withPathElement(ConstraintLocator::InstanceType));
44244412

44254413
// If matching of the instance types resulted in the failure make sure

0 commit comments

Comments
 (0)