Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -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'", ())

Expand Down
11 changes: 11 additions & 0 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion test/Sema/tilde_sendable.swift
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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) {
}
}