Skip to content

Commit 83dbd62

Browse files
committed
Test predatesConcurrency is only applied in Swift 5
Ensure that the predates concurrency behavior is only applied for Swift 5 and not for Swift 6.
1 parent 5a04344 commit 83dbd62

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func foo() -> Int {
2+
a + 10
3+
}

test/Concurrency/toplevel/main.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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()

0 commit comments

Comments
 (0)