Skip to content

Commit c4f0505

Browse files
author
Nathan Hawes
committed
[Parse] Don't drop throws containing a code completion expression.
1 parent 41ea927 commit c4f0505

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,7 @@ ParserResult<Stmt> Parser::parseStmtThrow(SourceLoc tryLoc) {
898898
exprLoc = Tok.getLoc();
899899

900900
ParserResult<Expr> Result = parseExpr(diag::expected_expr_throw);
901-
902-
if (Result.hasCodeCompletion())
903-
return makeParserCodeCompletionResult<Stmt>();
901+
bool hasCodeCompletion = Result.hasCodeCompletion();
904902

905903
if (Result.isNull())
906904
Result = makeParserErrorResult(new (Context) ErrorExpr(throwLoc));
@@ -916,6 +914,9 @@ ParserResult<Stmt> Parser::parseStmtThrow(SourceLoc tryLoc) {
916914
Result = makeParserResult(new (Context) TryExpr(exprLoc, Result.get()));
917915
}
918916

917+
if (hasCodeCompletion)
918+
Result.setHasCodeCompletion();
919+
919920
return makeParserResult(Result,
920921
new (Context) ThrowStmt(throwLoc, Result.get()));
921922
}

test/IDE/complete_exception.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=CATCH2 | %FileCheck %s -check-prefix=CATCH2
66
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=THROW2 | %FileCheck %s -check-prefix=THROW2
77
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=CATCH3 | %FileCheck %s -check-prefix=CATCH3
8+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=THROW3 | %FileCheck %s -check-prefix=THROW3
89
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_CATCH1 | %FileCheck %s -check-prefix=CATCH1
910
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_THROW1 | %FileCheck %s -check-prefix=THROW1
1011

1112
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_CATCH2 | %FileCheck %s -check-prefix=CATCH2
1213
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_THROW2 | %FileCheck %s -check-prefix=THROW2
14+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP_LEVEL_THROW3 | %FileCheck %s -check-prefix=THROW3
1315

1416
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=INSIDE_CATCH1 > %t.inside_catch1
1517
// RUN: %FileCheck %s -check-prefix=STMT < %t.inside_catch1
@@ -126,11 +128,20 @@ func test005() {
126128
// CATCH3: End completions
127129
}
128130

131+
func testInvalid() {
132+
try throw Error4.#^THROW3^#
133+
// THROW3: Begin completions
134+
// THROW3: Decl[EnumElement]/CurrNominal: E1[#Error4#]{{; name=.+$}}
135+
// THROW3: Decl[EnumElement]/CurrNominal: E2({#Int32#})[#Error4#]{{; name=.+$}}
136+
// THROW3: End completions
137+
}
138+
129139
//===--- Top-level throw/catch
130140
do {} catch #^TOP_LEVEL_CATCH1^# {}
131141
throw #^TOP_LEVEL_THROW1^#
132142
do {} catch Error4.#^TOP_LEVEL_CATCH2^# {}
133143
throw Error4.#^TOP_LEVEL_THROW2^#
144+
try throw Error4.#^TOP_LEVEL_THROW3^#
134145

135146
//===--- Inside catch body
136147

0 commit comments

Comments
 (0)