@@ -2457,6 +2457,7 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
2457
2457
layout = unwrappedToType->getExistentialLayout ();
2458
2458
requiresClass = layout.requiresClass ();
2459
2459
}
2460
+
2460
2461
if (requiresClass && !FromType->is <ClassType>()) {
2461
2462
return false ;
2462
2463
}
@@ -2470,8 +2471,7 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
2470
2471
2471
2472
diagnostic.flush ();
2472
2473
2473
- // Let's build a list of protocols that the contextual type does not
2474
- // conform to.
2474
+ // Let's build a list of protocols that the context does not conform to.
2475
2475
SmallVector<std::string, 8 > missingProtoTypeStrings;
2476
2476
for (auto protocol : layout.getProtocols ()) {
2477
2477
if (!getTypeChecker ().conformsToProtocol (
@@ -2483,19 +2483,22 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
2483
2483
2484
2484
// If we have a protocol composition type and we don't conform to all
2485
2485
// the protocols of the composition, then store the composition directly.
2486
+ // This is because we need to append 'Foo & Bar' instead of 'Foo, Bar' in
2487
+ // order to match the written type.
2486
2488
if (auto compositionTy = unwrappedToType->getAs <ProtocolCompositionType>()) {
2487
2489
if (compositionTy->getMembers ().size () == missingProtoTypeStrings.size ()) {
2488
2490
missingProtoTypeStrings = {compositionTy->getString ()};
2489
2491
}
2490
2492
}
2491
2493
2494
+ assert (!missingProtoTypeStrings.empty () &&
2495
+ " type already conforms to all the protocols?" );
2496
+
2492
2497
// If we didn't have a protocol composition type, it means we only have a
2493
2498
// single protocol, so just use it directly. Otherwise, construct a comma
2494
2499
// separated list of missing types.
2495
2500
std::string protoString;
2496
- if (missingProtoTypeStrings.empty ()) {
2497
- protoString = unwrappedToType->getString ();
2498
- } else if (missingProtoTypeStrings.size () == 1 ) {
2501
+ if (missingProtoTypeStrings.size () == 1 ) {
2499
2502
protoString = missingProtoTypeStrings.front ();
2500
2503
} else {
2501
2504
protoString = llvm::join (missingProtoTypeStrings, " , " );
0 commit comments