Skip to content

Commit df3aa1e

Browse files
authored
Merge pull request #85879 from xedin/add-supression-note-to-explicit-sendable-warning
[Diagnostics] TildeSendable: Suggest `Sendable` suppression in explic…
2 parents de9148e + f0fd506 commit df3aa1e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8979,6 +8979,9 @@ NOTE(sendable_conformance_is_suppressed, none,
89798979
"%kind0 explicitly suppresses conformance to 'Sendable' protocol",
89808980
(const NominalTypeDecl *))
89818981

8982+
NOTE(suppress_sendable_conformance,none,
8983+
"consider suppressing conformance to 'Sendable' protocol", ())
8984+
89828985
ERROR(non_sendable_type_suppressed,none,
89838986
"cannot both conform to and suppress conformance to 'Sendable'", ())
89848987

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,17 @@ void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
14531453
}
14541454
}
14551455

1456+
// Note to supress Sendable conformance is feature is enabled.
1457+
if (ctx.LangOpts.hasFeature(Feature::TildeSendable)) {
1458+
auto note = nominal->diagnose(diag::suppress_sendable_conformance);
1459+
auto inheritance = nominal->getInherited();
1460+
if (inheritance.empty()) {
1461+
note.fixItInsertAfter(nominal->getNameLoc(), ": ~Sendable");
1462+
} else {
1463+
note.fixItInsertAfter(inheritance.getEndLoc(), ", ~Sendable");
1464+
}
1465+
}
1466+
14561467
// Note to disable the warning.
14571468
{
14581469
auto note = nominal->diagnose(diag::explicit_disable_sendable, nominal);

test/Sema/tilde_sendable.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -strict-concurrency=complete -swift-version 5 -enable-experimental-feature TildeSendable
1+
// RUN: %target-typecheck-verify-swift -strict-concurrency=complete -swift-version 5 -enable-experimental-feature TildeSendable -Wwarning ExplicitSendable
22

33
// REQUIRES: swift_feature_TildeSendable
44

@@ -136,3 +136,19 @@ do {
136136
// expected-error@-1 {{conformance to 'Sendable' can only be suppressed on structs, classes, and enums}}
137137
}
138138
}
139+
140+
// ExplicitSendable + ~Sendable tests
141+
142+
public struct TestExplicitSendable1 { // expected-warning {{public struct 'TestExplicitSendable1' does not specify whether it is 'Sendable' or not}}
143+
// expected-note@-1 {{consider making struct 'TestExplicitSendable1' conform to the 'Sendable' protocol}}
144+
// expected-note@-2 {{consider suppressing conformance to 'Sendable' protocol}} {{36-36=: ~Sendable}}
145+
// expected-note@-3 {{make struct 'TestExplicitSendable1' explicitly non-Sendable to suppress this warning}}
146+
}
147+
148+
public class TestExplicitSendableWithParent: ExpressibleByIntegerLiteral { // expected-warning {{public class 'TestExplicitSendableWithParent' does not specify whether it is 'Sendable' or not}}
149+
// expected-note@-1 {{consider suppressing conformance to 'Sendable' protocol}} {{73-73=, ~Sendable}}
150+
// expected-note@-2 {{make class 'TestExplicitSendableWithParent' explicitly non-Sendable to suppress this warning}}
151+
152+
public required init(integerLiteral: Int) {
153+
}
154+
}

0 commit comments

Comments
 (0)