|
1 | | -// RUN: not %target-swift-frontend -enable-experimental-async-top-level -swift-version 6 -typecheck %s %S/Inputs/foo.swift 2>&1 | %FileCheck %s --check-prefixes='Swift6-CHECK,CHECK' |
2 | | -// RUN: not %target-swift-frontend -enable-experimental-async-top-level -swift-version 5 -typecheck %s %S/Inputs/foo.swift 2>&1 | %FileCheck %s --check-prefixes='Swift5-CHECK,CHECK' |
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file --leading-lines %s %t |
3 | 3 |
|
4 | | -var a = 10 |
| 4 | +// RUN: %target-swift-frontend -typecheck -verify %t/main.swift %t/foo.swift -enable-experimental-async-top-level -swift-version 6 -verify-additional-prefix swift6- |
| 5 | +// RUN: %target-swift-frontend -typecheck -verify %t/main.swift %t/foo.swift -enable-experimental-async-top-level -swift-version 5 -verify-additional-prefix swift5- |
| 6 | + |
| 7 | +//--- foo.swift |
| 8 | +func foo() -> Int { |
| 9 | + // expected-swift6-note@-1 {{add '@MainActor' to make global function 'foo()' part of global actor 'MainActor'}} |
| 10 | + a + 10 |
| 11 | + // expected-swift6-error@-1 {{main actor-isolated var 'a' can not be referenced from a nonisolated context}} |
| 12 | +} |
| 13 | + |
| 14 | +//--- main.swift |
| 15 | +var a = 10 // expected-swift6-note 2{{var declared here}} |
5 | 16 |
|
6 | 17 | @MainActor |
7 | | -var b = 14 |
8 | | -// CHECK: top-level code variables cannot have a global actor |
| 18 | +var b = 14 // expected-error {{top-level code variables cannot have a global actor}} |
9 | 19 |
|
10 | 20 | func nonIsolatedSynchronous() { |
| 21 | + // expected-swift6-note@-1 {{add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor'}} |
11 | 22 | print(a) |
12 | | -// Swift6-CHECK: main actor-isolated var 'a' can not be referenced from a nonisolated context |
13 | | -// Swift6-CHECK: add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor' |
14 | | - |
15 | | -// Swift5-CHECK-NOT: main actor-isolated var 'a' can not be referenced from a nonisolated context |
16 | | -// Swift5-CHECK-NOT: add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor' |
| 23 | +// expected-swift6-error@-1 {{main actor-isolated var 'a' can not be referenced from a nonisolated context}} |
17 | 24 | } |
18 | 25 |
|
19 | 26 | func nonIsolatedAsync() async { |
20 | | - print(a) |
21 | | -// CHECK: expression is 'async' but is not marked with 'await' |
22 | | -// CHECK: property access is 'async' |
| 27 | + print(a) |
| 28 | + // expected-swift6-error@-1 {{main actor-isolated var 'a' cannot be accessed from outside of the actor}} |
| 29 | + // expected-swift5-warning@-2 {{main actor-isolated var 'a' cannot be accessed from outside of the actor}} |
23 | 30 | } |
24 | 31 |
|
25 | 32 | await nonIsolatedAsync() |
26 | 33 |
|
27 | | -// Swift6-CHECK: foo.swift{{.*}}main actor-isolated var 'a' can not be referenced from a nonisolated context |
28 | | -// Swift6-CHECK-DAG: var declared here |
29 | | -// Swift6-CHECK-DAG: add '@MainActor' to make global function 'foo()' part of global actor 'MainActor' |
30 | | - |
31 | | -// Swift5-CHECK-NOT: foo.swift{{.*}}main actor-isolated var 'a' can not be referenced from a nonisolated context |
32 | | -// Swift5-CHECK-NOT: var declared here |
33 | | -// Swift5-CHECK-NOT: add '@MainActor' to make global function 'foo()' part of global actor 'MainActor' |
34 | | - |
35 | 34 | @MainActor |
36 | 35 | func isolated() { |
37 | | - print(a) |
| 36 | + print(a) |
38 | 37 | } |
39 | 38 |
|
40 | 39 | func asyncFun() async { |
41 | | - await print(a) |
| 40 | + await print(a) |
42 | 41 | } |
43 | 42 |
|
44 | 43 | await asyncFun() |
0 commit comments