|
1 |
| -// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify |
| 1 | +// RUN: %target-swift-frontend -swift-version 5 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift5- |
| 2 | +// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift6- |
2 | 3 |
|
3 | 4 | // READ THIS! This test is meant to check the specific isolation when
|
4 | 5 | // `-default-isolation` is set to `MainActor` in combination with validating
|
|
7 | 8 |
|
8 | 9 | // Fake Sendable Data
|
9 | 10 | class SendableData : @unchecked Sendable {}
|
| 11 | +// expected-swift5-note@-1 {{calls to initializer 'init()' from outside of its actor context are implicitly asynchronous}} |
10 | 12 |
|
11 | 13 | nonisolated func getDataFromSocket() -> SendableData { SendableData() }
|
| 14 | +// expected-swift5-warning@-1 {{call to main actor-isolated initializer 'init()' in a synchronous nonisolated context; this is an error in the Swift 6 language mode}} |
12 | 15 |
|
13 |
| -class Klass { // expected-note 3 {{}} |
| 16 | +class Klass { // expected-swift5-note 3 {{}} expected-swift6-note 3 {{}} |
14 | 17 | let s = SendableData()
|
| 18 | + // expected-swift5-note@-1 2 {{}} |
15 | 19 |
|
16 |
| - init() { s = SendableData() } |
| 20 | + init() { s = SendableData() } // expected-swift5-error {{immutable value 'self.s' may only be initialized once}} |
17 | 21 | init(_ s: SendableData) {}
|
18 | 22 |
|
19 | 23 | func doSomething() {}
|
@@ -50,9 +54,15 @@ func unspecifiedFunctionTest2() async {
|
50 | 54 |
|
51 | 55 | nonisolated func nonisolatedFunctionTest() async {
|
52 | 56 | let k = await StructContainingKlass()
|
53 |
| - await unspecifiedAsync(k.k) // expected-error {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
54 |
| - await nonisolatedAsync(k.k) // expected-error {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
55 |
| - await mainActorAsync(k.k) // expected-error {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
| 57 | + await unspecifiedAsync(k.k) |
| 58 | + // expected-swift5-warning@-1 {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
| 59 | + // expected-swift6-error@-2 {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
| 60 | + await nonisolatedAsync(k.k) |
| 61 | + // expected-swift5-warning@-1 {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
| 62 | + // expected-swift6-error@-2 {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
| 63 | + await mainActorAsync(k.k) |
| 64 | + // expected-swift5-warning@-1 {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
| 65 | + // expected-swift6-error@-2 {{non-sendable type 'Klass' of property 'k' cannot exit main actor-isolated context}} |
56 | 66 | }
|
57 | 67 |
|
58 | 68 | func testTask() async {
|
|
0 commit comments