@@ -1440,29 +1440,23 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
1440
1440
auto *locator = typeVar->getImpl ().getLocator ();
1441
1441
if (locator->isForGenericParameter ()) {
1442
1442
auto &CG = cs.getConstraintGraph ();
1443
- auto *repr = cs. getRepresentative (typeVar);
1444
- for ( auto *constraint : CG[repr]. getConstraints () ) {
1443
+
1444
+ auto isTransferableConformance = [&typeVar](Constraint *constraint ) {
1445
1445
if (constraint->getKind () != ConstraintKind::ConformsTo)
1446
- continue ;
1447
-
1448
- // This is not a direct requirement.
1449
- if (!constraint->getFirstType ()->isEqual (typeVar))
1450
- continue ;
1451
-
1452
- // If the composition consists of a class + protocol,
1453
- // we can't attach conformance to the argument because
1454
- // parameter would have to pick one of the components.
1455
- if (argTy.findIf ([](Type type) {
1456
- return type->is <ProtocolCompositionType>();
1457
- }))
1458
- continue ;
1459
-
1460
- auto protocolTy = constraint->getSecondType ();
1461
- if (!protocolTy->is <ProtocolType>())
1462
- continue ;
1463
-
1464
- cs.addConstraint (ConstraintKind::TransitivelyConformsTo, argTy,
1465
- protocolTy, constraint->getLocator ());
1446
+ return false ;
1447
+
1448
+ auto requirementTy = constraint->getFirstType ();
1449
+ if (!requirementTy->isEqual (typeVar))
1450
+ return false ;
1451
+
1452
+ return constraint->getSecondType ()->is <ProtocolType>();
1453
+ };
1454
+
1455
+ for (auto *constraint : CG[typeVar].getConstraints ()) {
1456
+ if (isTransferableConformance (constraint))
1457
+ cs.addConstraint (ConstraintKind::TransitivelyConformsTo, argTy,
1458
+ constraint->getSecondType (),
1459
+ constraint->getLocator ());
1466
1460
}
1467
1461
}
1468
1462
}
@@ -6250,6 +6244,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
6250
6244
if (resolvedTy->isTypeVariableOrMember ())
6251
6245
return formUnsolved ();
6252
6246
6247
+ // If the composition consists of a class + protocol,
6248
+ // we can't check conformance of the argument because
6249
+ // parameter could pick one of the components.
6250
+ if (resolvedTy.findIf (
6251
+ [](Type type) { return type->is <ProtocolCompositionType>(); }))
6252
+ return SolutionKind::Solved;
6253
+
6253
6254
auto *protocol = protocolTy->castTo <ProtocolType>()->getDecl ();
6254
6255
6255
6256
// First, let's check whether the type itself conforms,
0 commit comments