Skip to content

Commit 38e2998

Browse files
implement feedback changes
1 parent 42b9b48 commit 38e2998

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ bool MissingConformanceFailure::diagnoseTypeCannotConform(
474474
}
475475

476476
emitDiagnostic(diag::type_cannot_conform,
477-
nonConformingType->isExistentialType(), nonConformingType, nonConformingType->isEqual(protocolType),
477+
nonConformingType->isExistentialType(),
478+
nonConformingType,
479+
nonConformingType->isEqual(protocolType),
478480
protocolType);
479481

480482
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(AffectedDecl)) {
@@ -2061,7 +2063,8 @@ bool ContextualFailure::diagnoseAsError() {
20612063
if (CTP == CTP_ForEachStmt) {
20622064
if (fromType->isAnyExistentialType()) {
20632065
emitDiagnostic(diag::type_cannot_conform,
2064-
/*isExistentialType=*/true, fromType, fromType->isEqual(toType), toType);
2066+
/*isExistentialType=*/true, fromType,
2067+
fromType->isEqual(toType), toType);
20652068
return true;
20662069
}
20672070

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4256,7 +4256,8 @@ void swift::diagnoseConformanceFailure(Type T,
42564256

42574257
if (!T->isObjCExistentialType()) {
42584258
diags.diagnose(ComplainLoc, diag::type_cannot_conform, true,
4259-
T, T->isEqual(Proto->getDeclaredType()), Proto->getDeclaredType());
4259+
T, T->isEqual(Proto->getDeclaredType()),
4260+
Proto->getDeclaredType());
42604261
return;
42614262
}
42624263

userdocs/diagnostics/protocol-type-non-conformance.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var s: P = S() // This creates existential type because the protocol P is used a
1111
```
1212

1313
However, a protocol type does not conform to protocols - not even the protocol itself.
14-
Allowing existential types to conform to protocols is unsound because some protocol with static methods, initializers, or associated types requirements cannot be accessed from the protocol type itself - these kinds of requirements require a concrete type.
14+
Allowing existential types to conform to protocols is unsound. For protocols with static method, initializer, or associated type requirements, the implementation of these requirements cannot be accessed from the protocol type - accessing these kinds of requirements must be done using a concrete type.
15+
1516
Let's walk through the example below:
1617

1718
```swift
@@ -33,13 +34,13 @@ let pluralWord = Plural(word: "mangoes")
3334
let wordPairDict: [Word: Word] = [singularWord: pluralWord] // Error
3435
```
3536

36-
One workaround to fix this problem is to write a type erasure for the protocol `Word`. Think of type erasure as a way to hide an object's type. Since `Word` is of type `Hashable`, we already have `AnyHashable` type erasure available in the standard library which we can easily use here.
37+
One workaround to fix this problem is to use type erasure for the protocol `Word`. Think of type erasure as a way to hide an object's type. Since `Word` is of type `Hashable`, we already have `AnyHashable` type erasure available in the standard library which we can easily use here.
3738

3839
```swift
3940
// The fix
4041
let wordPairDict: [AnyHashable: AnyHashable] = [singularWord: pluralWord]
4142
```
4243

4344
# Exceptions
44-
`@objc` protocol type with no static requirements however do conform to its own protocol. One example is the `Error` protocol.
45+
`@objc` protocol type with no static requirements however do conform to its own protocol. Another exception is the `Error` Swift protocol.
4546

0 commit comments

Comments
 (0)