- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathasync.swift
82 lines (60 loc) · 2.97 KB
/
async.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// RUN: %target-typecheck-verify-swift -target %target-swift-5.1-abi-triple
// REQUIRES: concurrency
// Parsing function declarations with 'async'
func asyncGlobal1()async{}
func asyncGlobal2()asyncthrows{}
func asyncGlobal3()throwsasync{} // expected-error{{'async' must precede 'throws'}}{{28-34=}}{{21-21=async }}
func asyncGlobal3(fn:()throws->Int)rethrowsasync{} // expected-error{{'async' must precede 'rethrows'}}{{50-56=}}{{41-41=async }}
func asyncGlobal4()->Intasync{} // expected-error{{'async' may only occur before '->'}}{{28-34=}}{{21-21=async }}
func asyncGlobal5()->Intasyncthrows{}
// expected-error@-1{{'async' may only occur before '->'}}{{28-34=}}{{21-21=async }}
// expected-error@-2{{'throws' may only occur before '->'}}{{34-41=}}{{21-21=throws }}
func asyncGlobal6()->Intthrowsasync{}
// expected-error@-1{{'throws' may only occur before '->'}}{{28-35=}}{{21-21=throws }}
// expected-error@-2{{'async' may only occur before '->'}}{{35-41=}}{{21-21=async }}
func asyncGlobal7()throws->Intasync{} // expected-error{{'async' may only occur before '->'}}{{35-41=}}{{21-21=async }}
func asyncGlobal8()asyncthrowsasync->async Int async{}
// expected-error@-1{{'async' has already been specified}} {{34-40=}}
// expected-error@-2{{'async' has already been specified}} {{43-49=}}
// expected-error@-3{{'async' has already been specified}} {{53-59=}}
classX{
init()async{}
deinitasync{} // expected-error{{deinitializers cannot have a name}}
func f()async{}
subscript(x:Int)async->Int{ // expected-error{{expected '->' for subscript element type}}
// expected-error@-1{{single argument function types require parentheses}}
// expected-error@-2{{cannot find type 'async' in scope}}
// expected-note@-3{{cannot use module 'async' as a type}}
get{
return0
}
setasync{ // expected-error{{'set' accessor cannot have specifier 'async'}}
}
}
}
// Parsing function types with 'async'.
typealiasAsyncFunc1=()async->()
typealiasAsyncFunc2=()asyncthrows->()
typealiasAsyncFunc3=()throwsasync->() // expected-error{{'async' must precede 'throws'}}{{34-40=}}{{27-27=async }}
// Parsing type expressions with 'async'.
func testTypeExprs(){
let _ =[()async->()]()
let _ =[()asyncthrows->()]()
let _ =[()throwsasync->()]() // expected-error{{'async' must precede 'throws'}}{{22-28=}}{{15-15=async }}
let _ =[()->async()]() // expected-error{{'async' may only occur before '->'}}{{18-24=}}{{15-15=async }}
}
// Parsing await syntax.
structMyFuture{
func await()->Int{0}
}
func testAwaitExpr()async{
let _ =awaitasyncGlobal1()
letmyFuture=MyFuture()
let _ = myFuture.await()
}
func getIntSomeday()async->Int{5}
func testAsyncLet()async{
asyncletx=awaitgetIntSomeday()
_ =await x
}
asyncfunc asyncIncorrectly(){} // expected-error{{'async' must be written after the parameter list of a function}}{{1-7=}}{{30-30= async}}