@@ -3630,10 +3630,8 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
3630
3630
TypeMatchOptions subflags = TMF_GenerateConstraints;
3631
3631
3632
3632
// Handle opaque archetypes.
3633
- if (auto arch1 = type1->getAs<ArchetypeType>()) {
3634
- auto arch2 = type2->castTo<ArchetypeType>();
3635
- auto opaque1 = cast<OpaqueTypeArchetypeType>(arch1);
3636
- auto opaque2 = cast<OpaqueTypeArchetypeType>(arch2);
3633
+ if (auto opaque1 = type1->getAs<OpaqueTypeArchetypeType>()) {
3634
+ auto opaque2 = type2->castTo<OpaqueTypeArchetypeType>();
3637
3635
assert(opaque1->getDecl() == opaque2->getDecl());
3638
3636
3639
3637
// It's possible to declare a generic requirement like Self == Self.Iterator
@@ -3707,34 +3705,24 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
3707
3705
locator);
3708
3706
}
3709
3707
3710
- if (type1->isExistentialType()) {
3711
- auto layout1 = type1->getExistentialLayout();
3712
- auto layout2 = type2->getExistentialLayout ();
3708
+ // Members of protocol compositions have to match.
3709
+ if ( auto pct1 = type1->getAs<ProtocolCompositionType>()) {
3710
+ auto pct2 = type2->castTo<ProtocolCompositionType> ();
3713
3711
3714
- // Explicit AnyObject and protocols must match exactly.
3715
- if (layout1.hasExplicitAnyObject != layout2.hasExplicitAnyObject)
3712
+ auto members1 = pct1->getMembers();
3713
+ auto members2 = pct2->getMembers();
3714
+ if (members1.size() != members2.size())
3716
3715
return getTypeMatchFailure(locator);
3717
-
3718
- if (layout1.getProtocols().size() != layout2.getProtocols().size())
3716
+ if (pct1->getInverses() != pct2->getInverses())
3719
3717
return getTypeMatchFailure(locator);
3720
-
3721
- for (unsigned i: indices(layout1.getProtocols())) {
3722
- if (layout1.getProtocols()[i] != layout2.getProtocols()[i])
3723
- return getTypeMatchFailure(locator);
3724
- }
3725
-
3726
- // This is the only interesting case. We might have type variables
3727
- // on either side of the superclass constraint, so make sure we
3728
- // recursively call matchTypes() here.
3729
- if (layout1.explicitSuperclass || layout2.explicitSuperclass) {
3730
- if (!layout1.explicitSuperclass || !layout2.explicitSuperclass)
3731
- return getTypeMatchFailure(locator);
3732
-
3718
+ if (pct1->hasExplicitAnyObject() != pct2->hasExplicitAnyObject())
3719
+ return getTypeMatchFailure(locator);
3720
+ for (unsigned i = 0, e = members1.size(); i < e; ++i) {
3721
+ auto member1 = members1[i];
3722
+ auto member2 = members2[i];
3733
3723
auto subLocator = locator.withPathElement(
3734
- ConstraintLocator::ProtocolCompositionSuperclassType);
3735
- auto result = matchTypes(layout1.explicitSuperclass,
3736
- layout2.explicitSuperclass,
3737
- ConstraintKind::Bind, subflags,
3724
+ LocatorPathElt::ProtocolCompositionMemberType(i));
3725
+ auto result = matchTypes(member1, member2, ConstraintKind::Bind, subflags,
3738
3726
subLocator);
3739
3727
if (result.isFailure())
3740
3728
return result;
0 commit comments