-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Improve diagnostics for missing await
#37263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,26 +207,28 @@ extension BankAccount { | |
func totalBalance(including other: BankAccount) async -> Int { | ||
//expected-error@+1{{expression is 'async' but is not marked with 'await'}}{{12-12=await }} | ||
return balance() | ||
+ other.balance() // expected-note{{call is 'async'}} | ||
+ other.balance() // expected-note{{calls to instance method 'balance()' from outside of its actor context are implicitly asynchronous}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 Beautiful! |
||
} | ||
|
||
func breakAccounts(other: BankAccount) async { | ||
// expected-error@+1{{expression is 'async' but is not marked with 'await'}}{{9-9=await }} | ||
_ = other.deposit( // expected-note{{call is 'async'}} | ||
other.withdraw( // expected-note{{call is 'async'}} | ||
_ = other.deposit( // expected-note{{calls to instance method 'deposit' from outside of its actor context are implicitly asynchronous}} | ||
other.withdraw( // expected-note{{calls to instance method 'withdraw' from outside of its actor context are implicitly asynchronous}} | ||
self.deposit( | ||
other.withdraw( // expected-note{{call is 'async'}} | ||
other.balance())))) // expected-note{{call is 'async'}} | ||
other.withdraw( // expected-note{{calls to instance method 'withdraw' from outside of its actor context are implicitly asynchronous}} | ||
other.balance())))) // expected-note{{calls to instance method 'balance()' from outside of its actor context are implicitly asynchronous}} | ||
} | ||
} | ||
|
||
func anotherAsyncFunc() async { | ||
let a = BankAccount(initialDeposit: 34) | ||
let b = BankAccount(initialDeposit: 35) | ||
|
||
// expected-error@+1{{expression is 'async' but is not marked with 'await'}} {{7-7=await }} expected-note@+1{{call is 'async'}} | ||
// expected-error@+2{{expression is 'async' but is not marked with 'await'}} {{7-7=await }} | ||
// expected-note@+1{{calls to instance method 'deposit' from outside of its actor context are implicitly asynchronous}} | ||
_ = a.deposit(1) | ||
// expected-error@+1{{expression is 'async' but is not marked with 'await'}} {{7-7=await }} expected-note@+1{{call is 'async'}} | ||
// expected-error@+2{{expression is 'async' but is not marked with 'await'}} {{7-7=await }} | ||
// expected-note@+1{{calls to instance method 'balance()' from outside of its actor context are implicitly asynchronous}} | ||
_ = b.balance() | ||
|
||
_ = b.balance // expected-error {{actor-isolated instance method 'balance()' can only be referenced from inside the actor}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,12 +130,14 @@ func testTypesConcurrencyContext() async { | |
let _: () -> Int = f2 // expected-error{{converting function value of type '@SomeGlobalActor () -> Int' to '() -> Int' loses global actor 'SomeGlobalActor'}} | ||
|
||
// expected-error@+1{{expression is 'async' but is not marked with 'await'}}{{7-7=await }} | ||
_ = f1() //expected-note{{call is 'async}} | ||
_ = f1() //expected-note{{calls to let 'f1' from outside of its actor context are implicitly asynchronous}} | ||
// expected-error@+1{{expression is 'async' but is not marked with 'await'}}{{7-7=await }} | ||
_ = f2() //expected-note{{call is 'async'}} | ||
_ = f2() //expected-note{{calls to let 'f2' from outside of its actor context are implicitly asynchronous}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tiny nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, hmm...I wonder if changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if there's no prior art in the diagnostics for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something like e.g There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to keep thinking about this. There are other diagnostics (even near this line in the same file, basically anything that uses |
||
|
||
// expected-error@+1{{expression is 'async' but is not marked with 'await'}}{{7-7=await }} | ||
_ = f1() + f2() // expected-note 2 {{call is 'async'}} | ||
// expected-error@+3{{expression is 'async' but is not marked with 'await'}}{{7-7=await }} | ||
//expected-note@+2 {{calls to let 'f1' from outside of its actor context are implicitly asynchronous}} | ||
// expected-note@+1 {{calls to let 'f2' from outside of its actor context are implicitly asynchronous}} | ||
_ = f1() + f2() | ||
|
||
_ = await f1() | ||
_ = await f2() | ||
|
Uh oh!
There was an error while loading. Please reload this page.