|
7 | 7 | // MARK: Declarations //
|
8 | 8 | ////////////////////////
|
9 | 9 |
|
10 |
| -class NonSendableKlass {} |
| 10 | +class NonSendableKlass { |
| 11 | + func use() {} |
| 12 | +} |
11 | 13 |
|
12 | 14 | struct NonSendableStruct {
|
13 | 15 | var first = NonSendableKlass()
|
@@ -55,6 +57,9 @@ func throwingFunction() throws { fatalError() }
|
55 | 57 | func transferArg(_ x: sending NonSendableKlass) {
|
56 | 58 | }
|
57 | 59 |
|
| 60 | +func transferArgAsync(_ x: sending NonSendableKlass) async { |
| 61 | +} |
| 62 | + |
58 | 63 | func transferArgWithOtherParam(_ x: sending NonSendableKlass, _ y: NonSendableKlass) {
|
59 | 64 | }
|
60 | 65 |
|
@@ -559,3 +564,56 @@ extension MyActor {
|
559 | 564 | }
|
560 | 565 | }
|
561 | 566 | }
|
| 567 | + |
| 568 | +// We would normally not error here since transferArg is nonisolated and c is |
| 569 | +// disconnected. Since c is passed as sending, we shouldn't squelch this. |
| 570 | +func disconnectedPassedSendingToNonIsolatedCallee( |
| 571 | +) async -> Void { |
| 572 | + let c = NonSendableKlass() |
| 573 | + transferArg(c) // expected-warning {{sending 'c' risks causing data races}} |
| 574 | + // expected-note @-1 {{'c' used after being passed as a 'sending' parameter}} |
| 575 | + c.use() // expected-note {{access can happen concurrently}} |
| 576 | +} |
| 577 | + |
| 578 | +// We would normally not error here since transferArg is nonisolated and c is |
| 579 | +// disconnected. Since c is passed as sending, we shouldn't squelch this. |
| 580 | +func disconnectedPassedSendingToAsyncNonIsolatedCallee( |
| 581 | +) async -> Void { |
| 582 | + let c = NonSendableKlass() |
| 583 | + await transferArgAsync(c) // expected-warning {{sending 'c' risks causing data races}} |
| 584 | + // expected-note @-1 {{'c' used after being passed as a 'sending' parameter}} |
| 585 | + c.use() // expected-note {{access can happen concurrently}} |
| 586 | +} |
| 587 | + |
| 588 | +// We would normally not error here since transferArg is nonisolated and c is |
| 589 | +// disconnected. Since c is passed as sending, we shouldn't squelch this. |
| 590 | +func disconnectedPassedSendingToNonIsolatedCalleeIsolatedParam2( |
| 591 | + isolation: isolated (any Actor)? = nil |
| 592 | +) async -> Void { |
| 593 | + let c = NonSendableKlass() |
| 594 | + transferArg(c) // expected-warning {{sending 'c' risks causing data races}} |
| 595 | + // expected-note @-1 {{'c' used after being passed as a 'sending' parameter}} |
| 596 | + c.use() // expected-note {{access can happen concurrently}} |
| 597 | +} |
| 598 | + |
| 599 | +// We would normally not error here since transferArg is nonisolated and c is |
| 600 | +// disconnected. Since c is passed as sending, we shouldn't squelch this. |
| 601 | +func disconnectedPassedSendingToAsyncNonIsolatedCalleeIsolatedParam2( |
| 602 | + isolation: isolated (any Actor)? = nil |
| 603 | +) async -> Void { |
| 604 | + let c = NonSendableKlass() |
| 605 | + await transferArgAsync(c) // expected-warning {{sending 'c' risks causing data races}} |
| 606 | + // expected-note @-1 {{'c' used after being passed as a 'sending' parameter}} |
| 607 | + c.use() // expected-note {{access can happen concurrently}} |
| 608 | +} |
| 609 | + |
| 610 | +// We would normally not error here since transferArg is nonisolated and c is |
| 611 | +// disconnected. Since c is passed as sending, we shouldn't squelch this. |
| 612 | +func disconnectedPassedSendingToNonIsolatedCalleeIsolatedParam3( |
| 613 | + isolation: isolated (any Actor)? = nil |
| 614 | +) -> Void { |
| 615 | + let c = NonSendableKlass() |
| 616 | + transferArg(c) // expected-warning {{sending 'c' risks causing data races}} |
| 617 | + // expected-note @-1 {{'c' used after being passed as a 'sending' parameter}} |
| 618 | + c.use() // expected-note {{access can happen concurrently}} |
| 619 | +} |
0 commit comments