Skip to content

[CodeCompletion] Fix an issue that caused us to not produce any results for a guard condition inside a closure #71228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,17 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const {
FixKind::IgnoreCollectionElementContextualMismatch)) {
return llvm::None;
}
if (dstLocator->getAnchor().isExpr(ExprKind::CodeCompletion)) {
// Ignore the hole if it is because the right-hand-side of the pattern
// match is a code completion token. Assigning a high fix score to this
// mismatch won't help. In fact, it can harm because we might have a
// different exploration path in the constraint system that gives up
// earlier (eg. because code completion is in a closure that doesn't
// match the expected parameter of a function call) and might thus get a
// better score, despite not having any information about the code
// completion token at all.
return llvm::None;
}
// Not being able to infer the type of a variable in a pattern binding
// decl is more dramatic than anything that could happen inside the
// expression because we want to preferrably point the diagnostic to a
Expand Down
14 changes: 14 additions & 0 deletions test/IDE/complete_pattern_match_in_closure.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %batch-code-completion

func run(execute workItem: Int) {}
func run(execute work: () -> Void) {}

func test(myVar: Int) {
run {
guard let data = #^COMPLETE^# else {
return
}
}
}

// COMPLETE: Decl[LocalVar]/Local: myVar[#Int#]; name=myVar