Skip to content

Commit c48b77f

Browse files
committed
[CodeComplete] Don't skip single-expression AssignExpr bodies of an if/switch expr
Fix an issue uncovered by the stress tester where the brace element skipping logic could still attempt to skip a single-expression body of an if/switch expr.
1 parent 1dd86fc commit c48b77f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,13 @@ class SyntacticElementConstraintGenerator
11411141

11421142
for (auto element : braceStmt->getElements()) {
11431143
if (cs.isForCodeCompletion() &&
1144-
!cs.containsIDEInspectionTarget(element)) {
1144+
!cs.containsIDEInspectionTarget(element) &&
1145+
!(braceStmt->getSingleActiveExpression() &&
1146+
locator->isForSingleValueStmtConjunctionOrBrace())) {
11451147
// To improve performance, skip type checking elements that can't
1146-
// influence the code completion token.
1148+
// influence the code completion token. Note we don't do this for
1149+
// single expression SingleValueStmtExpr branches, as they're needed to
1150+
// infer the type.
11471151
if (element.is<Stmt *>() && !element.isStmt(StmtKind::Guard) && !element.isStmt(StmtKind::Return)) {
11481152
// Statements can't influence the expresion that contains the code
11491153
// completion token.

test/IDE/complete_if_switch_expr.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ func testSkipTypeChecking14() -> E {
335335
}
336336
}
337337

338+
func testSkipTypechecking15(_ x: inout Int) -> E {
339+
switch Bool.random() {
340+
case true:
341+
.#^DOT27?check=DOT^#
342+
case false:
343+
x = 0
344+
}
345+
}
338346

339347
// DOT: Begin completions, 2 items
340348
// DOT-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: e[#E#]; name=e

0 commit comments

Comments
 (0)