Skip to content

Commit 8997d3e

Browse files
committed
[TypeChecker/CodeCompletion] Re-introduce expression sanitization before solving
A call to `SanitizeExpr` has been incorrectly removed from `typeCheckForCodeCompletion` by refactoring to use `ASTNode`. It is still required because fallback calls could have partially type-checked AST. Resolves: #59315 Resolves: rdar://94619388 (cherry picked from commit 3159591)
1 parent 9692a83 commit 8997d3e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ bool TypeChecker::typeCheckForCodeCompletion(
575575
if (!node)
576576
return false;
577577

578+
if (auto *expr = getAsExpr(node)) {
579+
node = expr->walk(SanitizeExpr(Context,
580+
/*shouldReusePrecheckedType=*/false));
581+
}
582+
578583
CompletionContextFinder contextAnalyzer(node, DC);
579584

580585
// If there was no completion expr (e.g. if the code completion location was
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token COMPLETE
2+
3+
func foo(closure: (String) -> Void) -> String? {
4+
return nil
5+
}
6+
7+
func test() {
8+
if let key = foo(closure: { str in str.suffix(2) == #^COMPLETE^#

0 commit comments

Comments
 (0)