1
1
// RUN: %target-swift-frontend -typecheck -verify %s -enable-experimental-concurrency
2
2
3
3
func test1( asyncfp : ( ) async -> Int , fp : ( ) -> Int ) async {
4
- _ = __await asyncfp ( )
5
- _ = __await asyncfp ( ) + asyncfp( )
6
- _ = __await asyncfp ( ) + fp( )
7
- _ = __await fp( ) + 42 // expected-warning {{no calls to 'async' functions occur within 'await' expression}}
4
+ _ = await asyncfp ( )
5
+ _ = await asyncfp ( ) + asyncfp( )
6
+ _ = await asyncfp ( ) + fp( )
7
+ _ = await fp ( ) + 42 // expected-warning {{no calls to 'async' functions occur within 'await' expression}}
8
8
_ = asyncfp ( ) // expected-error {{call is 'async' but is not marked with 'await'}}
9
9
}
10
10
11
11
func getInt( ) async -> Int { return 5 }
12
12
13
13
// Locations where "await" is prohibited.
14
14
func test2(
15
- defaulted: Int = __await getInt( ) // expected-error{{'async' call cannot occur in a default argument}}
15
+ defaulted: Int = await getInt ( ) // expected-error{{'async' call cannot occur in a default argument}}
16
16
) async {
17
17
defer {
18
- _ = __await getInt( ) // expected-error{{'async' call cannot occur in a defer body}}
18
+ _ = await getInt ( ) // expected-error{{'async' call cannot occur in a defer body}}
19
19
}
20
20
print ( " foo " )
21
21
}
22
22
23
23
func test3( ) { // expected-note{{add 'async' to function 'test3()' to make it asynchronous}}
24
- _ = __await getInt( ) // expected-error{{'async' in a function that does not support concurrency}}
24
+ _ = await getInt ( ) // expected-error{{'async' in a function that does not support concurrency}}
25
25
}
26
26
27
27
enum SomeEnum : Int {
28
- case foo = __await 5 // expected-error{{raw value for enum case must be a literal}}
28
+ case foo = await 5 // expected-error{{raw value for enum case must be a literal}}
29
29
}
30
30
31
31
struct SomeStruct {
32
- var x = __await getInt( ) // expected-error{{'async' call cannot occur in a property initializer}}
33
- static var y = __await getInt( ) // expected-error{{'async' call cannot occur in a global variable initializer}}
32
+ var x = await getInt ( ) // expected-error{{'async' call cannot occur in a property initializer}}
33
+ static var y = await getInt ( ) // expected-error{{'async' call cannot occur in a global variable initializer}}
34
34
}
35
35
36
36
func acceptAutoclosureNonAsync( _: @autoclosure ( ) -> Int ) async { }
@@ -46,27 +46,27 @@ struct HasAsyncBad {
46
46
}
47
47
48
48
func testAutoclosure( ) async {
49
- __await acceptAutoclosureAsync( getInt ( ) ) // expected-error{{call is 'async' in an autoclosure argument is not marked with 'await'}}
50
- __await acceptAutoclosureNonAsync( getInt ( ) ) // expected-error{{'async' in an autoclosure that does not support concurrency}}
49
+ await acceptAutoclosureAsync ( getInt ( ) ) // expected-error{{call is 'async' in an autoclosure argument is not marked with 'await'}}
50
+ await acceptAutoclosureNonAsync ( getInt ( ) ) // expected-error{{'async' in an autoclosure that does not support concurrency}}
51
51
52
- __await acceptAutoclosureAsync( __await getInt( ) )
53
- __await acceptAutoclosureNonAsync( __await getInt( ) ) // expected-error{{'async' in an autoclosure that does not support concurrency}}
52
+ await acceptAutoclosureAsync ( await getInt ( ) )
53
+ await acceptAutoclosureNonAsync ( await getInt ( ) ) // expected-error{{'async' in an autoclosure that does not support concurrency}}
54
54
55
- __await acceptAutoclosureAsync( getInt ( ) ) // expected-error{{call is 'async' in an autoclosure argument is not marked with 'await'}}
56
- __await acceptAutoclosureNonAsync( getInt ( ) ) // expected-error{{'async' in an autoclosure that does not support concurrency}}
55
+ await acceptAutoclosureAsync ( getInt ( ) ) // expected-error{{call is 'async' in an autoclosure argument is not marked with 'await'}}
56
+ await acceptAutoclosureNonAsync ( getInt ( ) ) // expected-error{{'async' in an autoclosure that does not support concurrency}}
57
57
}
58
58
59
59
// Test inference of 'async' from the body of a closure.
60
60
func testClosure( ) {
61
61
let closure = {
62
- __await getInt( )
62
+ await getInt ( )
63
63
}
64
64
65
65
let _: ( ) -> Int = closure // expected-error{{cannot convert value of type '() async -> Int' to specified type '() -> Int'}}
66
66
67
67
let closure2 = { ( ) async -> Int in
68
68
print ( " here " )
69
- return __await getInt( )
69
+ return await getInt ( )
70
70
}
71
71
72
72
let _: ( ) -> Int = closure2 // expected-error{{cannot convert value of type '() async -> Int' to specified type '() -> Int'}}
0 commit comments