Skip to content

Commit edb9749

Browse files
xedinhamishknight
authored andcommitted
Revert "[CS] Account for type variables when matching metatypes"
This reverts commit 84a3db4.
1 parent 028795c commit edb9749

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
@@ -4394,34 +4394,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
43944394
auto meta1 = cast<AnyMetatypeType>(desugar1);
43954395
auto meta2 = cast<AnyMetatypeType>(desugar2);
43964396

4397-
auto instanceType1 = meta1->getInstanceType();
4398-
auto instanceType2 = meta2->getInstanceType();
4399-
44004397
// A.Type < B.Type if A < B and both A and B are classes.
44014398
// P.Type < Q.Type if P < Q, both P and Q are protocols, and P.Type
4402-
// and Q.Type are both existential metatypes.
4403-
auto getSubKind = [&]() -> ConstraintKind {
4404-
auto subKind = std::min(kind, ConstraintKind::Subtype);
4405-
4406-
// If we have existential metatypes, we need to perform subtyping.
4407-
if (!isa<MetatypeType>(meta1))
4408-
return subKind;
4409-
4410-
// If the LHS cannot be a type with a superclass, we can perform a bind.
4411-
if (!instanceType1->isTypeVariableOrMember() &&
4412-
!instanceType1->mayHaveSuperclass())
4413-
return ConstraintKind::Bind;
4414-
4415-
// If the RHS cannot be a class type, we can perform a bind.
4416-
if (!instanceType2->isTypeVariableOrMember() &&
4417-
!instanceType2->getClassOrBoundGenericClass())
4418-
return ConstraintKind::Bind;
4419-
4420-
return subKind;
4421-
};
4399+
// and Q.Type are both existential metatypes
4400+
auto subKind = std::min(kind, ConstraintKind::Subtype);
4401+
// If instance types can't have a subtype relationship
4402+
// it means that such types can be simply equated.
4403+
auto instanceType1 = meta1->getInstanceType();
4404+
auto instanceType2 = meta2->getInstanceType();
4405+
if (isa<MetatypeType>(meta1) &&
4406+
!(instanceType1->mayHaveSuperclass() &&
4407+
instanceType2->getClassOrBoundGenericClass())) {
4408+
subKind = ConstraintKind::Bind;
4409+
}
44224410

44234411
auto result =
4424-
matchTypes(instanceType1, instanceType2, getSubKind(), subflags,
4412+
matchTypes(instanceType1, instanceType2, subKind, subflags,
44254413
locator.withPathElement(ConstraintLocator::InstanceType));
44264414

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

0 commit comments

Comments
 (0)