Skip to content

Commit 2c719cc

Browse files
authored
Ensure that we warn about non-local non-@unchecked Sendable conformances. (#41102)
1 parent 9c5740f commit 2c719cc

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,10 +3979,9 @@ bool swift::checkSendableConformance(
39793979

39803980
// Sendable can only be used in the same source file.
39813981
auto conformanceDecl = conformanceDC->getAsDecl();
3982-
auto behavior = SendableCheckContext(conformanceDC)
3982+
auto behavior = SendableCheckContext(conformanceDC, check)
39833983
.defaultDiagnosticBehavior();
39843984
if (conformanceDC->getParentSourceFile() &&
3985-
nominal->getParentSourceFile() &&
39863985
conformanceDC->getParentSourceFile() != nominal->getParentSourceFile()) {
39873986
conformanceDecl->diagnose(diag::concurrent_value_outside_source_file,
39883987
nominal->getDescriptiveKind(),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
public class NonStrictClass { }
2+
3+
public struct NonStrictStruct { }

test/Concurrency/sendable_conformance_checking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ actor A10: AsyncThrowingProtocolWithNotSendable {
147147
}
148148

149149
// rdar://86653457 - Crash due to missing Sendable conformances.
150+
// expected-warning@+1{{non-final class 'Klass' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
150151
class Klass<Output: Sendable>: Sendable {}
151152
final class SubKlass: Klass<[S]> {}
152153
public struct S {}

test/Concurrency/sendable_module_checking.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ func testA(a: A) async {
1717
// CHECK: note: struct 'StrictStruct' does not conform to the 'Sendable' protocol
1818
// CHECK: note: class 'NonStrictClass' does not conform to the 'Sendable' protocol
1919
}
20+
21+
extension NonStrictStruct: @unchecked Sendable { }

test/decl/protocol/special/Actor.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ actor A7 {
4444
@available(SwiftStdlib 5.1, *)
4545
class C1: Actor {
4646
// expected-error@-1{{non-actor type 'C1' cannot conform to the 'Actor' protocol}}
47+
// expected-warning@-2{{non-final class 'C1' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
4748
nonisolated var unownedExecutor: UnownedSerialExecutor {
4849
fatalError("")
4950
}
@@ -52,6 +53,7 @@ class C1: Actor {
5253
@available(SwiftStdlib 5.1, *)
5354
class C2: Actor {
5455
// expected-error@-1{{non-actor type 'C2' cannot conform to the 'Actor' protocol}}
56+
// expected-warning@-2{{non-final class 'C2' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
5557
// FIXME: this should be an isolation violation
5658
var unownedExecutor: UnownedSerialExecutor {
5759
fatalError("")
@@ -62,6 +64,7 @@ class C2: Actor {
6264
class C3: Actor {
6365
// expected-error@-1{{type 'C3' does not conform to protocol 'Actor'}}
6466
// expected-error@-2{{non-actor type 'C3' cannot conform to the 'Actor' protocol}}
67+
// expected-warning@-3{{non-final class 'C3' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
6568
nonisolated func enqueue(_ job: UnownedJob) { }
6669
}
6770

0 commit comments

Comments
 (0)