Skip to content

Commit e8dcc97

Browse files
committed
fix-it regression coverage for notes suggesting 'async', '@asyncHandler' and '@GlobalActorType'
Currently, we don't have a fix-it to insert 'async', so I've marked those places as not expecting a fix-it, until someone goes and implements that (rdar://72313654)
1 parent e23f0ab commit e8dcc97

9 files changed

+42
-40
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ void swift::addAsyncNotes(AbstractFunctionDecl const* func) {
118118
if (!isa<DestructorDecl>(func))
119119
func->diagnose(diag::note_add_async_to_function, func->getName());
120120
// TODO: we need a source location for effects attributes so that we
121-
// can emit a fix-it.
121+
// can also emit a fix-it that inserts 'async' in the right place for func.
122+
// It's possibly a bit tricky to get the right source location from
123+
// just the AbstractFunctionDecl, but it's important to circle-back
124+
// to this.
122125

123126
if (func->canBeAsyncHandler()) {
124127
func->diagnose(

test/Concurrency/actor_call_implicitly_async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ func anotherAsyncFunc() async {
125125

126126
}
127127

128-
// expected-note@+2 {{add 'async' to function 'regularFunc()' to make it asynchronous}}
129-
// expected-note@+1 {{add '@asyncHandler' to function 'regularFunc()' to create an implicit asynchronous context}}
128+
// expected-note@+2 {{add 'async' to function 'regularFunc()' to make it asynchronous}} {{none}}
129+
// expected-note@+1 {{add '@asyncHandler' to function 'regularFunc()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
130130
func regularFunc() {
131131
let a = BankAccount(initialDeposit: 34)
132132

test/Concurrency/actor_isolation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension MyActor {
4444
set { }
4545
}
4646

47-
// expected-note@+1 {{add 'async' to function 'actorIndependentFunc(otherActor:)' to make it asynchronous}}
47+
// expected-note@+1 {{add 'async' to function 'actorIndependentFunc(otherActor:)' to make it asynchronous}} {{none}}
4848
@actorIndependent func actorIndependentFunc(otherActor: MyActor) -> Int {
4949
_ = immutable
5050
_ = text[0] // expected-error{{actor-isolated property 'text' can not be referenced from an '@actorIndependent' context}}
@@ -261,8 +261,8 @@ struct GenericStruct<T> {
261261
f() // okay
262262
}
263263

264-
// expected-note@+2 {{add '@asyncHandler' to function 'h()' to create an implicit asynchronous context}}
265-
// expected-note@+1 {{add 'async' to function 'h()' to make it asynchronous}}
264+
// expected-note@+2 {{add '@asyncHandler' to function 'h()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
265+
// expected-note@+1 {{add 'async' to function 'h()' to make it asynchronous}} {{none}}
266266
@GenericGlobalActor<String> func h() {
267267
f() // expected-error{{'async' in a function that does not support concurrency}}
268268
_ = f // expected-error{{instance method 'f()' isolated to global actor 'GenericGlobalActor<T>' can not be referenced from different global actor 'GenericGlobalActor<String>'}}

test/Concurrency/async_throwing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func throwingTask() async throws -> String {
4444
return "ok!"
4545
}
4646

47-
// expected-note@+2 7 {{add '@asyncHandler' to function 'syncTest()' to create an implicit asynchronous context}}
48-
// expected-note@+1 7 {{add 'async' to function 'syncTest()' to make it asynchronous}}
47+
// expected-note@+2 7 {{add '@asyncHandler' to function 'syncTest()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
48+
// expected-note@+1 7 {{add 'async' to function 'syncTest()' to make it asynchronous}} {{none}}
4949
func syncTest() {
5050
let _ = invoke(fn: normalTask) // expected-error{{'async' in a function that does not support concurrency}}
5151
let _ = invokeAuto(42) // expected-error{{'async' in a function that does not support concurrency}}

test/Concurrency/global_actor_from_ordinary_context.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ actor class Alex {
2727
}
2828

2929

30-
// expected-note@+1 4 {{add '@SomeGlobalActor' to make global function 'referenceGlobalActor()' part of global actor 'SomeGlobalActor'}}
30+
// expected-note@+1 4 {{add '@SomeGlobalActor' to make global function 'referenceGlobalActor()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
3131
func referenceGlobalActor() {
3232
let a = Alex()
3333
// expected-error@+1 {{instance method 'method()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
@@ -40,25 +40,25 @@ func referenceGlobalActor() {
4040
}
4141

4242

43-
// expected-note@+1 {{add '@SomeGlobalActor' to make global function 'referenceGlobalActor2()' part of global actor 'SomeGlobalActor'}}
43+
// expected-note@+1 {{add '@SomeGlobalActor' to make global function 'referenceGlobalActor2()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
4444
func referenceGlobalActor2() {
4545
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
4646
let x = syncGlobActorFn
4747
x()
4848
}
4949

5050

51-
// expected-note@+2 {{add '@asyncHandler' to function 'referenceAsyncGlobalActor()' to create an implicit asynchronous context}}
52-
// expected-note@+1 {{add 'async' to function 'referenceAsyncGlobalActor()' to make it asynchronous}}
51+
// expected-note@+2 {{add '@asyncHandler' to function 'referenceAsyncGlobalActor()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
52+
// expected-note@+1 {{add 'async' to function 'referenceAsyncGlobalActor()' to make it asynchronous}} {{none}}
5353
func referenceAsyncGlobalActor() {
5454
let y = asyncGlobalActFn
5555
y() // expected-error{{'async' in a function that does not support concurrency}}
5656
}
5757

5858

59-
// expected-note@+3 {{add '@asyncHandler' to function 'callGlobalActor()' to create an implicit asynchronous context}}
60-
// expected-note@+2 {{add 'async' to function 'callGlobalActor()' to make it asynchronous}}
61-
// expected-note@+1 {{add '@SomeGlobalActor' to make global function 'callGlobalActor()' part of global actor 'SomeGlobalActor'}}
59+
// expected-note@+3 {{add '@asyncHandler' to function 'callGlobalActor()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
60+
// expected-note@+2 {{add 'async' to function 'callGlobalActor()' to make it asynchronous}} {{none}}
61+
// expected-note@+1 {{add '@SomeGlobalActor' to make global function 'callGlobalActor()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
6262
func callGlobalActor() {
6363
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
6464
}
@@ -76,7 +76,7 @@ func fromClosure() {
7676
}
7777

7878
class Taylor {
79-
init() { // expected-note {{add 'async' to function 'init()' to make it asynchronous}}
79+
init() { // expected-note {{add 'async' to function 'init()' to make it asynchronous}} {{none}}
8080
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
8181

8282
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
@@ -90,17 +90,17 @@ class Taylor {
9090
_ = syncGlobActorFn
9191
}
9292

93-
// expected-note@+3 2 {{add '@SomeGlobalActor' to make instance method 'method1()' part of global actor 'SomeGlobalActor'}}
94-
// expected-note@+2 {{add '@asyncHandler' to function 'method1()' to create an implicit asynchronous context}}
95-
// expected-note@+1 {{add 'async' to function 'method1()' to make it asynchronous}}
93+
// expected-note@+3 2 {{add '@SomeGlobalActor' to make instance method 'method1()' part of global actor 'SomeGlobalActor'}} {{3-3=@SomeGlobalActor }}
94+
// expected-note@+2 {{add '@asyncHandler' to function 'method1()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
95+
// expected-note@+1 {{add 'async' to function 'method1()' to make it asynchronous}} {{none}}
9696
func method1() {
9797
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
9898

9999
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
100100
_ = syncGlobActorFn
101101
}
102102

103-
// expected-note@+2 2 {{add '@SomeGlobalActor' to make instance method 'cannotBeHandler()' part of global actor 'SomeGlobalActor'}}
103+
// expected-note@+2 2 {{add '@SomeGlobalActor' to make instance method 'cannotBeHandler()' part of global actor 'SomeGlobalActor'}} {{3-3=@SomeGlobalActor }}
104104
// expected-note@+1 {{add 'async' to function 'cannotBeHandler()' to make it asynchronous}}
105105
func cannotBeHandler() -> Int {
106106
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}

test/Concurrency/global_actor_inference.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ protocol P2 {
3535
class C1: P1 {
3636
func method() { } // expected-note {{calls to instance method 'method()' from outside of its actor context are implicitly asynchronous}}
3737

38-
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}}
39-
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}}
38+
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
39+
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}} {{none}}
4040
@OtherGlobalActor func testMethod() {
4141
method() // expected-error {{'async' in a function that does not support concurrency}}
4242
_ = method // expected-error {{instance method 'method()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
@@ -47,8 +47,8 @@ class C2: P2 {
4747
func method1() { } // expected-note{{calls to instance method 'method1()' from outside of its actor context are implicitly asynchronous}}
4848
func method2() { }
4949

50-
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}}
51-
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}}
50+
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
51+
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}} {{none}}
5252
@OtherGlobalActor func testMethod() {
5353
method1() // expected-error{{'async' in a function that does not support concurrency}}
5454
_ = method1 // expected-error{{instance method 'method1()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
@@ -83,8 +83,8 @@ class C5 {
8383
func method2() { } // expected-note {{calls to instance method 'method2()' from outside of its actor context are implicitly asynchronous}}
8484
}
8585

86-
// expected-note@+2 5 {{add '@asyncHandler' to function 'testGlobalActorInference(c3:c4:c5:)' to create an implicit asynchronous context}}
87-
// expected-note@+1 5 {{add 'async' to function 'testGlobalActorInference(c3:c4:c5:)' to make it asynchronous}}
86+
// expected-note@+2 5 {{add '@asyncHandler' to function 'testGlobalActorInference(c3:c4:c5:)' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
87+
// expected-note@+1 5 {{add 'async' to function 'testGlobalActorInference(c3:c4:c5:)' to make it asynchronous}} {{none}}
8888
@OtherGlobalActor func testGlobalActorInference(c3: C3, c4: C4, c5: C5) {
8989
// Propagation via class annotation
9090
c3.method1() // expected-error{{'async' in a function that does not support concurrency}}
@@ -145,8 +145,8 @@ actor class GenericSub<T> : GenericSuper<[T]> {
145145
@GenericGlobalActor<T> override func method2() { } // expected-error{{global actor 'GenericGlobalActor<T>'-isolated instance method 'method2()' has different actor isolation from global actor 'GenericGlobalActor<[T]>'-isolated overridden declaration}}
146146
@actorIndependent override func method3() { } // expected-error{{actor-independent instance method 'method3()' has different actor isolation from global actor 'GenericGlobalActor<[T]>'-isolated overridden declaration}}
147147

148-
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}}
149-
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}}
148+
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
149+
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}} {{none}}
150150
@OtherGlobalActor func testMethod() {
151151
method() // expected-error{{'async' in a function that does not support concurrency}}
152152
_ = method // expected-error{{instance method 'method()' isolated to global actor 'GenericGlobalActor<[T]>' can not be referenced from different global actor 'OtherGlobalActor'}}
@@ -190,9 +190,9 @@ func bar() async {
190190
foo() // expected-error{{call is 'async' but is not marked with 'await'}}
191191
}
192192

193-
// expected-note@+3 {{add '@SomeGlobalActor' to make global function 'barSync()' part of global actor 'SomeGlobalActor'}}
194-
// expected-note@+2 {{add '@asyncHandler' to function 'barSync()' to create an implicit asynchronous context}}
195-
// expected-note@+1 {{add 'async' to function 'barSync()' to make it asynchronous}}
193+
// expected-note@+3 {{add '@SomeGlobalActor' to make global function 'barSync()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
194+
// expected-note@+2 {{add '@asyncHandler' to function 'barSync()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
195+
// expected-note@+1 {{add 'async' to function 'barSync()' to make it asynchronous}} {{none}}
196196
func barSync() {
197197
foo() // expected-error {{'async' in a function that does not support concurrency}}
198198
}

test/attr/asynchandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class Y: P {
6060
// @asyncHandler is not inferred for classes
6161

6262
func callback() {
63-
// expected-note@-1{{add 'async' to function 'callback()' to make it asynchronous}}
64-
// expected-note@-2{{add '@asyncHandler' to function 'callback()' to create an implicit asynchronous context}}
63+
// expected-note@-1{{add 'async' to function 'callback()' to make it asynchronous}} {{none}}
64+
// expected-note@-2{{add '@asyncHandler' to function 'callback()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
6565

6666
// okay, it's an async context
6767
let _ = await globalAsyncFunction() // expected-error{{'async' in a function that does not support concurrency}}

test/attr/attr_objc_async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ actor class MyActor {
3737

3838
// Actor-isolated entities cannot be exposed to Objective-C.
3939
@objc func synchronousBad() { } // expected-error{{actor-isolated instance method 'synchronousBad()' cannot be @objc}}
40-
// expected-note@-1{{add 'async' to function 'synchronousBad()' to make it asynchronous}}
41-
// expected-note@-2{{add '@asyncHandler' to function 'synchronousBad()' to create an implicit asynchronous context}}
40+
// expected-note@-1{{add 'async' to function 'synchronousBad()' to make it asynchronous}} {{none}}
41+
// expected-note@-2{{add '@asyncHandler' to function 'synchronousBad()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
4242

4343
@objc var badProp: AnyObject { self } // expected-error{{actor-isolated property 'badProp' cannot be @objc}}
4444
@objc subscript(index: Int) -> AnyObject { self } // expected-error{{actor-isolated subscript 'subscript(_:)' cannot be @objc}}

test/expr/unary/async_await.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func test2(
2222
print("foo")
2323
}
2424

25-
func test3() { // expected-note{{add 'async' to function 'test3()' to make it asynchronous}}
25+
func test3() { // expected-note{{add 'async' to function 'test3()' to make it asynchronous}} {{none}}
2626
// expected-note@-1{{add '@asyncHandler' to function 'test3()' to create an implicit asynchronous context}}{{1-1=@asyncHandler }}
2727
_ = await getInt() // expected-error{{'async' in a function that does not support concurrency}}
2828
}
@@ -41,7 +41,7 @@ func acceptAutoclosureAsync(_: @autoclosure () async -> Int) async { }
4141

4242
func acceptAutoclosureNonAsyncBad(_: @autoclosure () async -> Int) -> Int { 0 }
4343
// expected-error@-1{{'async' autoclosure parameter in a non-'async' function}}
44-
// expected-note@-2{{add 'async' to function 'acceptAutoclosureNonAsyncBad' to make it asynchronous}}
44+
// expected-note@-2{{add 'async' to function 'acceptAutoclosureNonAsyncBad' to make it asynchronous}} {{none}}
4545

4646
struct HasAsyncBad {
4747
init(_: @autoclosure () async -> Int) { }
@@ -183,13 +183,12 @@ func testAsyncLet() async throws {
183183
_ = await x5
184184
}
185185

186-
// expected-note@+2 4{{add 'async' to function 'testAsyncLetOutOfAsync()' to make it asynchronous}}
187-
// expected-note@+1 4{{add '@asyncHandler' to function 'testAsyncLetOutOfAsync()' to create an implicit asynchronous context}}
186+
// expected-note@+2 4{{add 'async' to function 'testAsyncLetOutOfAsync()' to make it asynchronous}} {{none}}
187+
// expected-note@+1 4{{add '@asyncHandler' to function 'testAsyncLetOutOfAsync()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
188188
func testAsyncLetOutOfAsync() {
189189
async let x = 1 // expected-error{{'async let' in a function that does not support concurrency}}
190190
// FIXME: expected-error@-1{{'async' in a function that does not support concurrency}}
191191

192192
_ = await x // expected-error{{'async let' in a function that does not support concurrency}}
193193
_ = x // expected-error{{'async let' in a function that does not support concurrency}}
194194
}
195-

0 commit comments

Comments
 (0)