File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -368,7 +368,8 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
368
368
// Parse an async specifier.
369
369
SourceLoc asyncLoc;
370
370
if (shouldParseExperimentalConcurrency () &&
371
- Tok.isContextualKeyword (" async" )) {
371
+ Tok.isContextualKeyword (" async" ) &&
372
+ peekToken ().isAny (tok::arrow, tok::kw_throws)) {
372
373
asyncLoc = consumeToken ();
373
374
}
374
375
Original file line number Diff line number Diff line change @@ -10,6 +10,23 @@ func asyncGlobal3() throws async { } // expected-error{{'async' must precede 'th
10
10
11
11
func asyncGlobal3( fn: ( ) throws -> Int ) rethrows async { } // expected-error{{'async' must precede 'rethrows'}}{{50-56=}}{{41-41=async }}
12
12
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
+
13
30
class X {
14
31
init ( ) async { } // expected-error{{initializer cannot be marked 'async'}}
15
32
You can’t perform that action at this time.
0 commit comments