@@ -3286,7 +3286,41 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
32863286 }
32873287
32883288 // Handle existential types.
3289- if (type1->isExistentialType() && type2->isExistentialType()) {
3289+ if (auto *existential1 = type1->getAs<ExistentialType>()) {
3290+ auto existential2 = type2->castTo<ExistentialType>();
3291+
3292+ auto result = matchTypes(existential1->getConstraintType(),
3293+ existential2->getConstraintType(),
3294+ ConstraintKind::Bind, subflags,
3295+ locator.withPathElement(
3296+ ConstraintLocator::ExistentialConstraintType));
3297+
3298+ if (result.isFailure())
3299+ return result;
3300+
3301+ return getTypeMatchSuccess();
3302+ }
3303+
3304+ // Arguments of parameterized protocol types have to match on the nose.
3305+ if (auto ppt1 = type1->getAs<ParameterizedProtocolType>()) {
3306+ auto ppt2 = type2->castTo<ParameterizedProtocolType>();
3307+
3308+ auto result = matchTypes(ppt1->getBaseType(),
3309+ ppt2->getBaseType(),
3310+ ConstraintKind::Bind, subflags,
3311+ locator.withPathElement(
3312+ ConstraintLocator::ParentType));
3313+
3314+ if (result.isFailure())
3315+ return result;
3316+
3317+ return matchDeepTypeArguments(*this, subflags,
3318+ ppt1->getArgs(),
3319+ ppt2->getArgs(),
3320+ locator);
3321+ }
3322+
3323+ if (type1->isExistentialType()) {
32903324 auto layout1 = type1->getExistentialLayout();
32913325 auto layout2 = type2->getExistentialLayout();
32923326
@@ -3309,24 +3343,16 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
33093343 if (!layout1.explicitSuperclass || !layout2.explicitSuperclass)
33103344 return getTypeMatchFailure(locator);
33113345
3346+ auto subLocator = locator.withPathElement(
3347+ ConstraintLocator::ProtocolCompositionSuperclassType);
33123348 auto result = matchTypes(layout1.explicitSuperclass,
33133349 layout2.explicitSuperclass,
33143350 ConstraintKind::Bind, subflags,
3315- locator.withPathElement(
3316- ConstraintLocator::ExistentialSuperclassType));
3351+ subLocator);
33173352 if (result.isFailure())
33183353 return result;
33193354 }
33203355
3321- // Arguments of parameterized protocol types have to match on the nose.
3322- if (auto ppt1 = type1->getAs<ParameterizedProtocolType>()) {
3323- auto ppt2 = type2->castTo<ParameterizedProtocolType>();
3324- return matchDeepTypeArguments(*this, subflags,
3325- ppt1->getArgs(),
3326- ppt2->getArgs(),
3327- locator);
3328- }
3329-
33303356 return getTypeMatchSuccess();
33313357 }
33323358
@@ -6367,7 +6393,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
63676393 // If we are matching types for equality, we might still have
63686394 // type variables inside the protocol composition's superclass
63696395 // constraint.
6370- conversionsOrFixes.push_back(ConversionRestrictionKind::DeepEquality);
6396+ if (desugar1->getKind() == desugar2->getKind())
6397+ conversionsOrFixes.push_back(ConversionRestrictionKind::DeepEquality);
63716398 break;
63726399
63736400 default:
0 commit comments