mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Fix await in effect with async
Typing `func foo() await {` is something that folks do from time-to-time.
The old error message was unintuitive and suggested adding a semicolon
between the parenthesis and the await, then proceeded to complain about
the opening brace. This wasn't very clear about what the error actually
was.
Pulling this in line with `try`, `throw`, and `throws`, this patch
suggests replacing `await` with `async` when in the function effect
position, and provides a nice fix-it.
This commit is contained in:
@@ -926,6 +926,7 @@ bool Parser::isEffectsSpecifier(const Token &T) {
|
||||
// 'parseEffectsSpecifiers()'.
|
||||
|
||||
if (T.isContextualKeyword("async") ||
|
||||
(T.isContextualKeyword("await") && !T.isAtStartOfLine()) ||
|
||||
T.isContextualKeyword("reasync"))
|
||||
return true;
|
||||
|
||||
@@ -984,6 +985,13 @@ ParserStatus Parser::parseEffectsSpecifiers(SourceLoc existingArrowLoc,
|
||||
consumeToken();
|
||||
continue;
|
||||
}
|
||||
// diagnose 'await'
|
||||
if (Tok.isContextualKeyword("await") && !Tok.isAtStartOfLine()) {
|
||||
diagnose(Tok, diag::await_in_function_type)
|
||||
.fixItReplace(Tok.getLoc(), "async");
|
||||
consumeToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
// 'throws'/'rethrows', or diagnose 'throw'/'try'.
|
||||
if (Tok.isAny(tok::kw_throws, tok::kw_rethrows) ||
|
||||
|
||||
Reference in New Issue
Block a user