File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
test/Concurrency/toplevel Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ func foo( ) -> Int {
2
+ a + 10
3
+ }
Original file line number Diff line number Diff line change
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'
3
+
4
+ var a = 10
5
+
6
+ func nonIsolatedSynchronous( ) {
7
+ print ( a)
8
+ // Swift6-CHECK: var 'a' isolated to global actor 'MainActor'
9
+ // Swift6-CHECK: add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor'
10
+
11
+ // Swift5-CHECK-NOT: var 'a' isolated to global actor 'MainActor'
12
+ // Swift5-CHECK-NOT: add '@MainActor' to make global function 'nonIsolatedSynchronous()' part of global actor 'MainActor'
13
+ }
14
+
15
+ func nonIsolatedAsync( ) async {
16
+ print ( a)
17
+ // CHECK: expression is 'async' but is not marked with 'await'
18
+ // CHECK: property access is 'async'
19
+ }
20
+
21
+ await nonIsolatedAsync ( )
22
+
23
+ // Swift6-CHECK: foo.swift{{.*}}var 'a' isolated to global actor 'MainActor' can not be referenced from this synchronous context
24
+ // Swift6-CHECK: foo.swift{{.*}}add '@MainActor' to make global function 'foo()' part of global actor 'MainActor'
25
+ // Swift6-CHECK: var declared here
26
+
27
+ // Swift5-CHECK-NOT: foo.swift{{.*}}var 'a' isolated to global actor 'MainActor' can not be referenced from this synchronous context
28
+ // Swift5-CHECK-NOT: foo.swift{{.*}}add '@MainActor' to make global function 'foo()' part of global actor 'MainActor'
29
+ // Swift5-CHECK-NOT: var declared here
30
+
31
+ @MainActor
32
+ func isolated( ) {
33
+ print ( a)
34
+ }
35
+
36
+ func asyncFun( ) async {
37
+ await print ( a)
38
+ }
39
+
40
+ await asyncFun ( )
You can’t perform that action at this time.
0 commit comments