Skip to content

Commit 9384813

Browse files
committed
[Diagnostics] Split "only concrete types conform to protocols" into a separate note
1 parent 92fe04f commit 9384813

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,9 +1842,11 @@ ERROR(use_of_equal_instead_of_equality,none,
18421842
"use of '=' in a boolean context, did you mean '=='?", ())
18431843
ERROR(type_cannot_conform, none,
18441844
"%select{type %1|protocol %1 as a type}0 cannot conform to "
1845-
"%select{%3|the protocol itself}2; "
1846-
"only concrete types such as structs, enums and classes can conform to protocols",
1845+
"%select{%3|the protocol itself}2",
18471846
(bool, Type, bool, Type))
1847+
NOTE(only_concrete_types_conform_to_protocols,none,
1848+
"only concrete types such as structs, enums and classes can conform to protocols",
1849+
())
18481850
NOTE(required_by_opaque_return,none,
18491851
"required by opaque return type of %0 %1", (DescriptiveDeclKind, DeclName))
18501852
NOTE(required_by_decl,none,

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ bool MissingConformanceFailure::diagnoseTypeCannotConform(
516516
nonConformingType->isEqual(protocolType),
517517
protocolType);
518518

519+
emitDiagnostic(diag::only_concrete_types_conform_to_protocols);
520+
519521
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(AffectedDecl)) {
520522
auto *namingDecl = OTD->getNamingDecl();
521523
if (auto *repr = namingDecl->getOpaqueResultTypeRepr()) {
@@ -2171,6 +2173,7 @@ bool ContextualFailure::diagnoseAsError() {
21712173
emitDiagnostic(diag::type_cannot_conform,
21722174
/*isExistentialType=*/true, fromType,
21732175
fromType->isEqual(toType), toType);
2176+
emitDiagnostic(diag::only_concrete_types_conform_to_protocols);
21742177
return true;
21752178
}
21762179

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4735,6 +4735,8 @@ void swift::diagnoseConformanceFailure(Type T,
47354735
diags.diagnose(ComplainLoc, diag::type_cannot_conform, true,
47364736
T, T->isEqual(Proto->getDeclaredInterfaceType()),
47374737
Proto->getDeclaredInterfaceType());
4738+
diags.diagnose(ComplainLoc,
4739+
diag::only_concrete_types_conform_to_protocols);
47384740
return;
47394741
}
47404742

0 commit comments

Comments
 (0)