Merge pull request #85879 from xedin/add-supression-note-to-explicit-sendable-warning

[Diagnostics] TildeSendable: Suggest `Sendable` suppression in explic…
This commit is contained in:
Pavel Yaskevich
2025-12-08 13:29:25 -08:00
committed by GitHub
3 changed files with 31 additions and 1 deletions

View File

@@ -8979,6 +8979,9 @@ NOTE(sendable_conformance_is_suppressed, none,
"%kind0 explicitly suppresses conformance to 'Sendable' protocol",
(const NominalTypeDecl *))
NOTE(suppress_sendable_conformance,none,
"consider suppressing conformance to 'Sendable' protocol", ())
ERROR(non_sendable_type_suppressed,none,
"cannot both conform to and suppress conformance to 'Sendable'", ())

View File

@@ -1453,6 +1453,17 @@ void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
}
}
// Note to supress Sendable conformance is feature is enabled.
if (ctx.LangOpts.hasFeature(Feature::TildeSendable)) {
auto note = nominal->diagnose(diag::suppress_sendable_conformance);
auto inheritance = nominal->getInherited();
if (inheritance.empty()) {
note.fixItInsertAfter(nominal->getNameLoc(), ": ~Sendable");
} else {
note.fixItInsertAfter(inheritance.getEndLoc(), ", ~Sendable");
}
}
// Note to disable the warning.
{
auto note = nominal->diagnose(diag::explicit_disable_sendable, nominal);

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -strict-concurrency=complete -swift-version 5 -enable-experimental-feature TildeSendable
// RUN: %target-typecheck-verify-swift -strict-concurrency=complete -swift-version 5 -enable-experimental-feature TildeSendable -Wwarning ExplicitSendable
// REQUIRES: swift_feature_TildeSendable
@@ -136,3 +136,19 @@ do {
// expected-error@-1 {{conformance to 'Sendable' can only be suppressed on structs, classes, and enums}}
}
}
// ExplicitSendable + ~Sendable tests
public struct TestExplicitSendable1 { // expected-warning {{public struct 'TestExplicitSendable1' does not specify whether it is 'Sendable' or not}}
// expected-note@-1 {{consider making struct 'TestExplicitSendable1' conform to the 'Sendable' protocol}}
// expected-note@-2 {{consider suppressing conformance to 'Sendable' protocol}} {{36-36=: ~Sendable}}
// expected-note@-3 {{make struct 'TestExplicitSendable1' explicitly non-Sendable to suppress this warning}}
}
public class TestExplicitSendableWithParent: ExpressibleByIntegerLiteral { // expected-warning {{public class 'TestExplicitSendableWithParent' does not specify whether it is 'Sendable' or not}}
// expected-note@-1 {{consider suppressing conformance to 'Sendable' protocol}} {{73-73=, ~Sendable}}
// expected-note@-2 {{make class 'TestExplicitSendableWithParent' explicitly non-Sendable to suppress this warning}}
public required init(integerLiteral: Int) {
}
}