Skip to content

Commit 29c818f

Browse files
committed
---
yaml --- r: 343551 b: refs/heads/master-rebranch c: c7088ff h: refs/heads/master i: 343549: 5d68459 343547: 989f9d6 343543: 997d36e 343535: 02c6ab9 343519: b792e6a 343487: 017a73a 343423: 743a2cd 343295: b097238 343039: ac9f22a
1 parent 0bbf285 commit 29c818f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 5a1f06a1ef2350a7cd0b656f72b6bae4432fa630
1458+
refs/heads/master-rebranch: c7088ffd41eb6cb8b4cf038fb7d07e9190e23fcd
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,7 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
24572457
layout = unwrappedToType->getExistentialLayout();
24582458
requiresClass = layout.requiresClass();
24592459
}
2460+
24602461
if (requiresClass && !FromType->is<ClassType>()) {
24612462
return false;
24622463
}
@@ -2470,8 +2471,7 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
24702471

24712472
diagnostic.flush();
24722473

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.
24752475
SmallVector<std::string, 8> missingProtoTypeStrings;
24762476
for (auto protocol : layout.getProtocols()) {
24772477
if (!getTypeChecker().conformsToProtocol(
@@ -2483,19 +2483,22 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
24832483

24842484
// If we have a protocol composition type and we don't conform to all
24852485
// 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.
24862488
if (auto compositionTy = unwrappedToType->getAs<ProtocolCompositionType>()) {
24872489
if (compositionTy->getMembers().size() == missingProtoTypeStrings.size()) {
24882490
missingProtoTypeStrings = {compositionTy->getString()};
24892491
}
24902492
}
24912493

2494+
assert(!missingProtoTypeStrings.empty() &&
2495+
"type already conforms to all the protocols?");
2496+
24922497
// If we didn't have a protocol composition type, it means we only have a
24932498
// single protocol, so just use it directly. Otherwise, construct a comma
24942499
// separated list of missing types.
24952500
std::string protoString;
2496-
if (missingProtoTypeStrings.empty()) {
2497-
protoString = unwrappedToType->getString();
2498-
} else if (missingProtoTypeStrings.size() == 1) {
2501+
if (missingProtoTypeStrings.size() == 1) {
24992502
protoString = missingProtoTypeStrings.front();
25002503
} else {
25012504
protoString = llvm::join(missingProtoTypeStrings, ", ");

0 commit comments

Comments
 (0)