Skip to content

Commit 4d29c8a

Browse files
committed
[region-isolation] Add some warning->error tests.
Just increasing code coverage.
1 parent 9ff4094 commit 4d29c8a

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

test/Concurrency/transfernonsendable_warning_until_swift6.swift

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,35 @@ func testIsolationError() async {
2525
useValue(x) // expected-note {{access here could race}}
2626
}
2727

28-
func testArgumentError(_ x: NonSendableType) async { // expected-note {{value is task isolated since it is in the same region as 'x'}}
28+
func testTransferArgumentError(_ x: NonSendableType) async { // expected-note {{value is task isolated since it is in the same region as 'x'}}
2929
await transferToMain(x) // expected-error {{task isolated value of type 'NonSendableType' transferred to main actor-isolated context; later accesses to value could race}}
3030
}
3131

32-
func testTransferringArgument(_ x: NonSendableType) async {
32+
func testPassArgumentAsTransferringParameter(_ x: NonSendableType) async {
3333
transferValue(x) // expected-error {{task isolated value of type 'NonSendableType' passed as a strongly transferred parameter; later accesses could race}}
3434
}
35+
36+
func testAssignmentIntoTransferringParameter(_ x: transferring NonSendableType) async {
37+
let y = NonSendableType()
38+
x = y // expected-error {{transferring value of non-Sendable type 'NonSendableType' into transferring parameter; later accesses could race}}
39+
useValue(y) // expected-note {{access here could race}}
40+
}
41+
42+
func testAssigningParameterIntoTransferringParameter(_ x: transferring NonSendableType, _ y: NonSendableType) async {
43+
x = y // expected-error {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
44+
}
45+
46+
func testIsolationCrossingDueToCapture() async {
47+
let x = NonSendableType()
48+
let _ = { @MainActor in
49+
print(x) // expected-error {{main actor-isolated closure captures value of non-Sendable type 'NonSendableType' from nonisolated context; later accesses to value could race}}
50+
}
51+
useValue(x) // expected-note {{access here could race}}
52+
}
53+
54+
func testIsolationCrossingDueToCaptureParameter(_ x: NonSendableType) async {
55+
let _ = { @MainActor in
56+
print(x) // expected-error {{task isolated value of type 'NonSendableType' transferred to main actor-isolated context; later accesses to value could race}}
57+
}
58+
useValue(x)
59+
}

0 commit comments

Comments
 (0)