- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathexecution_behavior_attrs.swift
86 lines (62 loc) · 3.54 KB
/
execution_behavior_attrs.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
83
84
85
86
// RUN: %target-typecheck-verify-swift -disable-availability-checking
// REQUIRES: concurrency
typealiasF=@concurrent()async->Void
typealiasE=@concurrent()->Void
// expected-error@-1 {{cannot use '@concurrent' on non-async function type}}
func test1(_: nonisolated(nonsending)(Int...)async->Void){}
func test2(_:@concurrent(Int...)async->Void){}
func test_err1_concurrent(_:@concurrent@MainActor()async->Void){}
// expected-error@-1 {{cannot use '@concurrent' because function type is isolated to a global actor 'MainActor'}}
func test_err1_caller(_: nonisolated(nonsending)@MainActor()async->Void){}
// expected-error@-1 {{cannot use 'nonisolated(nonsending)' because function type is isolated to a global actor 'MainActor'}}
func test_err2_concurrent(_:@concurrent@isolated(any)()async->Void){}
// expected-error@-1 {{cannot use '@concurrent' together with '@isolated(any)'}}
func test_err2_caller(_: nonisolated(nonsending)@isolated(any)()async->Void){}
// expected-error@-1 {{cannot use 'nonisolated(nonsending)' together with '@isolated(any)'}}
func test_err3_concurrent(_:@concurrent(isolated(any Actor)?)async->Void){}
// expected-error@-1 {{cannot use '@concurrent' together with an isolated parameter}}
func test_err3_caller(_: nonisolated(nonsending)(isolated (anyActor)?)async->Void){}
// expected-error@-1 {{cannot use 'nonisolated(nonsending)' together with an isolated parameter}}
func test_err4(_: nonisolated (Int)->Void){}
// expected-error@-1 {{expected 'nonsending' in modifier}}
// expected-error@-2 {{expected '{' in body of function declaration}}
// expected-warning@-3 {{extraneous whitespace between attribute name and '('; this is an error in the Swift 6 language mode}}
// expected-error@-4 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-5 {{expected expression}}
func test_err5(_: nonisolated(()async->Void){}
// expected-error@-1 {{expected 'nonsending' in modifier}}
func test_err6(_: nonisolated(hello)()async->Void){}
// expected-error@-1 {{expected 'nonsending' in modifier}}
// expected-error@-2 {{cannot have more than one parameter list}}
// expected-error@-3 {{cannot find type 'hello' in scope}}
// expected-error@-4 {{onsecutive statements on a line must be separated by ';'}}
// expected-error@-5 {{expected expression}}
func test_err7(_:nonisolated(hello ()async->Void){}
// expected-error@-1 {{expected 'nonsending' in modifier}}
// expected-error@-2 {{cannot find type 'hello' in scope}}
func test_err8(_:@concurrentInt){} // expected-error {{attribute does not apply to type}}
do{
let _ =[nonisolated(nonsending)()async->Void]()
let _ =[nonisolated(nonsending)()-> Void]()
// expected-error@-1 {{cannot use 'nonisolated(nonsending)' on non-async function type}}
}
protocolP{}
structS:nonisolated
P { // Ok
}
do{
func nonisolated(){}
// `nonisolated` is parsed as a function call
nonisolated // expected-error {{function is unused}}
(42) // expected-warning {{integer literal is unused}}
let _:nonisolated // expected-error {{cannot find type 'nonisolated' in scope}}
(Int)async-> Void // expected-error {{expected member name or initializer call after type name}}
// expected-note@-1 {{use '.self' to reference the type object}}
// expected-warning@-2 {{expression of type '((Int) async -> Void).Type' is unused}}
_ =[nonisolated()]
}
do{
func nonisolated(_:Int)->Int{42}
nonisolated(0) // expected-warning {{result of call to 'nonisolated' is unused}}
print("hello")
}