Skip to content

Commit 7b6f45c

Browse files
authored
Merge pull request #71228 from ahoppen/ahoppen/complete-in-guard
[CodeCompletion] Fix an issue that caused us to not produce any results for a `guard` condition inside a closure
2 parents 192d275 + 2016f09 commit 7b6f45c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,17 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const {
25222522
FixKind::IgnoreCollectionElementContextualMismatch)) {
25232523
return llvm::None;
25242524
}
2525+
if (dstLocator->getAnchor().isExpr(ExprKind::CodeCompletion)) {
2526+
// Ignore the hole if it is because the right-hand-side of the pattern
2527+
// match is a code completion token. Assigning a high fix score to this
2528+
// mismatch won't help. In fact, it can harm because we might have a
2529+
// different exploration path in the constraint system that gives up
2530+
// earlier (eg. because code completion is in a closure that doesn't
2531+
// match the expected parameter of a function call) and might thus get a
2532+
// better score, despite not having any information about the code
2533+
// completion token at all.
2534+
return llvm::None;
2535+
}
25252536
// Not being able to infer the type of a variable in a pattern binding
25262537
// decl is more dramatic than anything that could happen inside the
25272538
// expression because we want to preferrably point the diagnostic to a
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %batch-code-completion
2+
3+
func run(execute workItem: Int) {}
4+
func run(execute work: () -> Void) {}
5+
6+
func test(myVar: Int) {
7+
run {
8+
guard let data = #^COMPLETE^# else {
9+
return
10+
}
11+
}
12+
}
13+
14+
// COMPLETE: Decl[LocalVar]/Local: myVar[#Int#]; name=myVar

0 commit comments

Comments
 (0)