Skip to content

Commit e0e3f05

Browse files
committed
Parse Type after seeing and consuming throws
1 parent 995f5ac commit e0e3f05

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lib/Parse/ParsePattern.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -848,20 +848,20 @@ void Parser::parseAsyncThrows(
848848
diagnose(Tok, diag::throw_in_function_type)
849849
.fixItReplace(Tok.getLoc(), "throws");
850850
}
851-
852-
StringRef keyword = Tok.getText();
853-
throwsLoc = consumeToken();
854-
855-
if (!peekToken().isKeyword()) {
856-
BacktrackingScope backtrackingScope(*this);
857-
if (peekToken().is(tok::kw_throws)) {
858-
ASTContext &Ctx = SF.getASTContext();
859-
DiagnosticSuppression SuppressedDiags(Ctx.Diags);
860-
backtrackingScope.cancelBacktrack();
861-
if (canParseType()) {
862-
ParserResult<TypeRepr> result = parseType();
863-
throwsType = result.getPtrOrNull();
864-
}
851+
StringRef keyword;
852+
if (Tok.isKeyword() && Tok.is(tok::kw_throws)) {
853+
keyword = Tok.getText();
854+
throwsLoc = consumeToken();
855+
ASTContext &Ctx = SF.getASTContext();
856+
DiagnosticSuppression SuppressedDiags(Ctx.Diags);
857+
bool hasType = false;
858+
{
859+
BacktrackingScope backtrack(*this);
860+
hasType = canParseType();
861+
}
862+
if (hasType) {
863+
ParserResult<TypeRepr> result = parseType();
864+
throwsType = result.getPtrOrNull();
865865
}
866866
}
867867

test/Parse/errors.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ func one() {
4242

4343
func foo() throws {}
4444

45-
struct SomeError: Error {}
45+
struct SomeError: Swift.Error {}
4646

4747
func bar() throws SomeError {}
48+
49+
func baz() throws SomeError -> Int { return 2; }
4850

4951
do {
5052
#if false

0 commit comments

Comments
 (0)