Skip to content

Commit 0bbf285

Browse files
committed
---
yaml --- r: 343550 b: refs/heads/master-rebranch c: 5a1f06a h: refs/heads/master
1 parent 5d68459 commit 0bbf285

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
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: 666c000607214d1fb42b4157e468e78b9d0bb779
1458+
refs/heads/master-rebranch: 5a1f06a1ef2350a7cd0b656f72b6bae4432fa630
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: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,8 +2452,10 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
24522452
// If the protocol requires a class & we don't have one (maybe the context
24532453
// is a struct), then bail out instead of offering a broken fix-it later on.
24542454
auto requiresClass = false;
2455+
ExistentialLayout layout;
24552456
if (unwrappedToType->isExistentialType()) {
2456-
requiresClass = unwrappedToType->getExistentialLayout().requiresClass();
2457+
layout = unwrappedToType->getExistentialLayout();
2458+
requiresClass = layout.requiresClass();
24572459
}
24582460
if (requiresClass && !FromType->is<ClassType>()) {
24592461
return false;
@@ -2469,23 +2471,20 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
24692471
diagnostic.flush();
24702472

24712473
// Let's build a list of protocols that the contextual type does not
2472-
// conform to. We will start by first checking if we have a protocol
2473-
// composition type and add all the individual types that the context
2474-
// does not conform to.
2474+
// conform to.
24752475
SmallVector<std::string, 8> missingProtoTypeStrings;
2476-
if (auto compositionTy = unwrappedToType->getAs<ProtocolCompositionType>()) {
2477-
for (auto memberTy : compositionTy->getMembers()) {
2478-
auto protocol = memberTy->getAnyNominal()->getSelfProtocolDecl();
2479-
if (!getTypeChecker().conformsToProtocol(
2480-
FromType, protocol, getDC(),
2481-
ConformanceCheckFlags::InExpression)) {
2482-
missingProtoTypeStrings.push_back(memberTy->getString());
2483-
}
2476+
for (auto protocol : layout.getProtocols()) {
2477+
if (!getTypeChecker().conformsToProtocol(
2478+
FromType, protocol->getDecl(), getDC(),
2479+
ConformanceCheckFlags::InExpression)) {
2480+
missingProtoTypeStrings.push_back(protocol->getString());
24842481
}
2485-
// If we don't conform to all of the protocols in the composition, then
2486-
// store the composition type only. This is because we need to append
2487-
// 'Foo & Bar' instead of 'Foo, Bar' in order to match the written type.
2488-
if (missingProtoTypeStrings.size() == compositionTy->getMembers().size()) {
2482+
}
2483+
2484+
// If we have a protocol composition type and we don't conform to all
2485+
// the protocols of the composition, then store the composition directly.
2486+
if (auto compositionTy = unwrappedToType->getAs<ProtocolCompositionType>()) {
2487+
if (compositionTy->getMembers().size() == missingProtoTypeStrings.size()) {
24892488
missingProtoTypeStrings = {compositionTy->getString()};
24902489
}
24912490
}

0 commit comments

Comments
 (0)