From f0fd5067459c37009e8c9b1d669e7428359fb276 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Fri, 5 Dec 2025 17:12:37 -0800 Subject: [PATCH] [Diagnostics] TildeSendable: Suggest `Sendable` suppression in explicit Senable warning Add a note to missing explicit `Sendable` conformance warning (produced by `-Wwarning ExplicitSendable`) and a fix-it with a suggestion to suppress `Senable` conformance via `~Sendable`. --- include/swift/AST/DiagnosticsSema.def | 3 +++ lib/Sema/TypeCheckConcurrency.cpp | 11 +++++++++++ test/Sema/tilde_sendable.swift | 18 +++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 116e11f825d1e..18c57099ae575 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -8987,6 +8987,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'", ()) diff --git a/lib/Sema/TypeCheckConcurrency.cpp b/lib/Sema/TypeCheckConcurrency.cpp index 1fa26a342f119..a7937c445a4a3 100644 --- a/lib/Sema/TypeCheckConcurrency.cpp +++ b/lib/Sema/TypeCheckConcurrency.cpp @@ -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); diff --git a/test/Sema/tilde_sendable.swift b/test/Sema/tilde_sendable.swift index 0e1be14a6535e..7c5de87fd0285 100644 --- a/test/Sema/tilde_sendable.swift +++ b/test/Sema/tilde_sendable.swift @@ -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) { + } +}