@@ -3630,10 +3630,8 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
36303630 TypeMatchOptions subflags = TMF_GenerateConstraints;
36313631
36323632 // 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>();
36373635 assert(opaque1->getDecl() == opaque2->getDecl());
36383636
36393637 // It's possible to declare a generic requirement like Self == Self.Iterator
@@ -3707,34 +3705,24 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
37073705 locator);
37083706 }
37093707
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> ();
37133711
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())
37163715 return getTypeMatchFailure(locator);
3717-
3718- if (layout1.getProtocols().size() != layout2.getProtocols().size())
3716+ if (pct1->getInverses() != pct2->getInverses())
37193717 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];
37333723 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,
37383726 subLocator);
37393727 if (result.isFailure())
37403728 return result;
0 commit comments