Skip to content

Commit 8581027

Browse files
committed
[Concurrency] Fix fix-it for async after ->
The `async` was being incorrectly consumed in `parseType` and as a result, was not getting propagated back up to `parseFunctionSignature` to be emitted as an error. Unless the next token is an arrow or a throws, we don't consume it.
1 parent 23b8dba commit 8581027

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Parse/ParseType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
368368
// Parse an async specifier.
369369
SourceLoc asyncLoc;
370370
if (shouldParseExperimentalConcurrency() &&
371-
Tok.isContextualKeyword("async")) {
371+
Tok.isContextualKeyword("async") &&
372+
peekToken().isAny(tok::arrow, tok::kw_throws)) {
372373
asyncLoc = consumeToken();
373374
}
374375

test/Parse/async.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ func asyncGlobal3() throws async { } // expected-error{{'async' must precede 'th
1010

1111
func asyncGlobal3(fn: () throws -> Int) rethrows async { } // expected-error{{'async' must precede 'rethrows'}}{{50-56=}}{{41-41=async }}
1212

13+
func asyncGlobal4() -> Int async { } // expected-error{{'async' may only occur before '->'}}{{28-34=}}{{21-21=async }}
14+
15+
// If both async and throws follow the return type in the correct order,
16+
// throws will get the error and fix-it first. Applying the fix-it will cause
17+
// the async error and fix-it to be emitted. Applying that will place the async
18+
// in the appropriate place.
19+
20+
// expected-error@+1{{'throws' may only occur before '->'}}{{34-41=}}{{21-21=throws }}
21+
func asyncGlobal5() -> Int async throws { }
22+
23+
// If they are in the wrong order, the first fix-it will put them in the right
24+
// order and will be the same as the above case
25+
// expected-error@+1{{'async' must precede 'throws'}}{{35-41=}}{{28-28=async }}
26+
func asyncGlobal6() -> Int throws async { }
27+
28+
func asyncGlobal7() throws -> Int async { } // expected-error{{'async' may only occur before '->'}}{{35-41=}}{{28-28=async }}
29+
1330
class X {
1431
init() async { } // expected-error{{initializer cannot be marked 'async'}}
1532

0 commit comments

Comments
 (0)