Skip to content

Commit 7e65384

Browse files
author
Nathan Hawes
authored
Merge pull request #35535 from nathawes/dont-filter-out-non-best-solutions-for-completion
[CodeCompletion][Sema] Don't filter out any viable solutions when solving for code completion
2 parents 3a05086 + 3fe0b8f commit 7e65384

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@ class ConstraintSystem {
27852785
void
27862786
filterSolutions(SmallVectorImpl<Solution> &solutions,
27872787
bool minimize = false) {
2788-
if (solutions.size() < 2)
2788+
if (solutions.size() < 2 || isForCodeCompletion())
27892789
return;
27902790

27912791
if (auto best = findBestSolution(solutions, minimize)) {

test/IDE/complete_ambiguous.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=MULTICLOSURE_FUNCBUILDER_ERROR | %FileCheck %s --check-prefix=POINT_MEMBER
4747
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=MULTICLOSURE_FUNCBUILDER_FIXME | %FileCheck %s --check-prefix=NORESULTS
4848
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=REGULAR_MULTICLOSURE_APPLIED | %FileCheck %s --check-prefix=POINT_MEMBER
49+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=BEST_SOLUTION_FILTER | %FileCheck %s --check-prefix=BEST_SOLUTION_FILTER
50+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=BEST_SOLUTION_FILTER2 | %FileCheck %s --check-prefix=BEST_SOLUTION_FILTER
4951

5052

5153
struct A {
@@ -438,3 +440,23 @@ takesClosureOfPoint { p in
438440
if p.#^REGULAR_MULTICLOSURE_APPLIED^# {}
439441
}
440442
}
443+
444+
enum Enum123 {
445+
case enumElem
446+
}
447+
struct Struct123: Equatable {
448+
var structMem = Enum123.enumElem
449+
}
450+
func testNoBestSolutionFilter() {
451+
let a = Struct123();
452+
let b = [Struct123]().first(where: { $0 == a && 1 + 90 * 5 / 8 == 45 * -10 })?.structMem != .#^BEST_SOLUTION_FILTER^#
453+
let c = min(10.3, 10 / 10.4) < 6 + 5 / (10 - 3) ? true : Optional(a)?.structMem != .#^BEST_SOLUTION_FILTER2^#
454+
}
455+
456+
// BEST_SOLUTION_FILTER: Begin completions
457+
// BEST_SOLUTION_FILTER-DAG: Decl[EnumElement]/ExprSpecific/TypeRelation[Convertible]: enumElem[#Enum123#]{{; name=.+$}}
458+
// BEST_SOLUTION_FILTER-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): Enum123#})[#(into: inout Hasher) -> Void#]{{; name=.+$}}
459+
// BEST_SOLUTION_FILTER-DAG: Keyword[nil]/None/Erase[1]/TypeRelation[Identical]: nil[#Enum123?#]{{; name=.+$}}
460+
// BEST_SOLUTION_FILTER-DAG: Decl[EnumElement]/CurrNominal/IsSystem/TypeRelation[Identical]: none[#Optional<Enum123>#]{{; name=.+$}}
461+
// BEST_SOLUTION_FILTER-DAG: Decl[EnumElement]/CurrNominal/IsSystem/TypeRelation[Identical]: some({#Enum123#})[#Optional<Enum123>#]{{; name=.+$}}
462+
// BEST_SOLUTION_FILTER: End completions

0 commit comments

Comments
 (0)