Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
fix-it regression coverage for notes suggesting 'async', '@asyncHandl…
Browse files Browse the repository at this point in the history
…er' 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)
  • Loading branch information
kavon committed Dec 14, 2020
1 parent e23f0ab commit e8dcc97
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 40 deletions.
5 changes: 4 additions & 1 deletion lib/Sema/TypeCheckConcurrency.cpp
Expand Up @@ -118,7 +118,10 @@ void swift::addAsyncNotes(AbstractFunctionDecl const* func) {
if (!isa<DestructorDecl>(func))
func->diagnose(diag::note_add_async_to_function, func->getName());
// TODO: we need a source location for effects attributes so that we
// can emit a fix-it.
// can also emit a fix-it that inserts 'async' in the right place for func.
// It's possibly a bit tricky to get the right source location from
// just the AbstractFunctionDecl, but it's important to circle-back
// to this.

if (func->canBeAsyncHandler()) {
func->diagnose(
Expand Down
4 changes: 2 additions & 2 deletions test/Concurrency/actor_call_implicitly_async.swift
Expand Up @@ -125,8 +125,8 @@ func anotherAsyncFunc() async {

}

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

Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/actor_isolation.swift
Expand Up @@ -44,7 +44,7 @@ extension MyActor {
set { }
}

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

// expected-note@+2 {{add '@asyncHandler' to function 'h()' to create an implicit asynchronous context}}
// expected-note@+1 {{add 'async' to function 'h()' to make it asynchronous}}
// expected-note@+2 {{add '@asyncHandler' to function 'h()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
// expected-note@+1 {{add 'async' to function 'h()' to make it asynchronous}} {{none}}
@GenericGlobalActor<String> func h() {
f() // expected-error{{'async' in a function that does not support concurrency}}
_ = f // expected-error{{instance method 'f()' isolated to global actor 'GenericGlobalActor<T>' can not be referenced from different global actor 'GenericGlobalActor<String>'}}
Expand Down
4 changes: 2 additions & 2 deletions test/Concurrency/async_throwing.swift
Expand Up @@ -44,8 +44,8 @@ func throwingTask() async throws -> String {
return "ok!"
}

// expected-note@+2 7 {{add '@asyncHandler' to function 'syncTest()' to create an implicit asynchronous context}}
// expected-note@+1 7 {{add 'async' to function 'syncTest()' to make it asynchronous}}
// expected-note@+2 7 {{add '@asyncHandler' to function 'syncTest()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
// expected-note@+1 7 {{add 'async' to function 'syncTest()' to make it asynchronous}} {{none}}
func syncTest() {
let _ = invoke(fn: normalTask) // expected-error{{'async' in a function that does not support concurrency}}
let _ = invokeAuto(42) // expected-error{{'async' in a function that does not support concurrency}}
Expand Down
24 changes: 12 additions & 12 deletions test/Concurrency/global_actor_from_ordinary_context.swift
Expand Up @@ -27,7 +27,7 @@ actor class Alex {
}


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


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


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


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

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

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

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

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

// expected-note@+2 2 {{add '@SomeGlobalActor' to make instance method 'cannotBeHandler()' part of global actor 'SomeGlobalActor'}}
// expected-note@+2 2 {{add '@SomeGlobalActor' to make instance method 'cannotBeHandler()' part of global actor 'SomeGlobalActor'}} {{3-3=@SomeGlobalActor }}
// expected-note@+1 {{add 'async' to function 'cannotBeHandler()' to make it asynchronous}}
func cannotBeHandler() -> Int {
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
Expand Down
22 changes: 11 additions & 11 deletions test/Concurrency/global_actor_inference.swift
Expand Up @@ -35,8 +35,8 @@ protocol P2 {
class C1: P1 {
func method() { } // expected-note {{calls to instance method 'method()' from outside of its actor context are implicitly asynchronous}}

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

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

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

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

// expected-note@+3 {{add '@SomeGlobalActor' to make global function 'barSync()' part of global actor 'SomeGlobalActor'}}
// expected-note@+2 {{add '@asyncHandler' to function 'barSync()' to create an implicit asynchronous context}}
// expected-note@+1 {{add 'async' to function 'barSync()' to make it asynchronous}}
// expected-note@+3 {{add '@SomeGlobalActor' to make global function 'barSync()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
// expected-note@+2 {{add '@asyncHandler' to function 'barSync()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
// expected-note@+1 {{add 'async' to function 'barSync()' to make it asynchronous}} {{none}}
func barSync() {
foo() // expected-error {{'async' in a function that does not support concurrency}}
}
4 changes: 2 additions & 2 deletions test/attr/asynchandler.swift
Expand Up @@ -60,8 +60,8 @@ class Y: P {
// @asyncHandler is not inferred for classes

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

// okay, it's an async context
let _ = await globalAsyncFunction() // expected-error{{'async' in a function that does not support concurrency}}
Expand Down
4 changes: 2 additions & 2 deletions test/attr/attr_objc_async.swift
Expand Up @@ -37,8 +37,8 @@ actor class MyActor {

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

@objc var badProp: AnyObject { self } // expected-error{{actor-isolated property 'badProp' cannot be @objc}}
@objc subscript(index: Int) -> AnyObject { self } // expected-error{{actor-isolated subscript 'subscript(_:)' cannot be @objc}}
Expand Down
9 changes: 4 additions & 5 deletions test/expr/unary/async_await.swift
Expand Up @@ -22,7 +22,7 @@ func test2(
print("foo")
}

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

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

struct HasAsyncBad {
init(_: @autoclosure () async -> Int) { }
Expand Down Expand Up @@ -183,13 +183,12 @@ func testAsyncLet() async throws {
_ = await x5
}

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

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

0 comments on commit e8dcc97

Please sign in to comment.