@@ -2064,9 +2064,20 @@ Constraint *ConstraintSystem::getUnboundBindOverloadDisjunction(
20642064
20652065// Performance hack: if there are two generic overloads, and one is
20662066// more specialized than the other, prefer the more-specialized one.
2067- static Constraint *tryOptimizeGenericDisjunction (
2068- DeclContext *dc,
2069- ArrayRef<Constraint *> constraints) {
2067+ static Constraint *
2068+ tryOptimizeGenericDisjunction (ConstraintSystem &cs, Constraint *disjunction,
2069+ ArrayRef<Constraint *> constraints) {
2070+ auto *dc = cs.DC ;
2071+
2072+ // If we're solving for code completion, and have a child completion token,
2073+ // skip this optimization since the completion token being a placeholder can
2074+ // allow us to prefer an unhelpful disjunction choice.
2075+ if (cs.isForCodeCompletion ()) {
2076+ auto anchor = disjunction->getLocator ()->getAnchor ();
2077+ if (cs.containsIDEInspectionTarget (cs.includingParentApply (anchor)))
2078+ return nullptr ;
2079+ }
2080+
20702081 llvm::SmallVector<Constraint *, 4 > choices;
20712082 for (auto *choice : constraints) {
20722083 if (choices.size () > 2 )
@@ -2311,7 +2322,7 @@ void DisjunctionChoiceProducer::partitionDisjunction(
23112322 SmallVectorImpl<unsigned > &PartitionBeginning) {
23122323 // Apply a special-case rule for favoring one generic function over
23132324 // another.
2314- if (auto favored = tryOptimizeGenericDisjunction (CS. DC , Choices)) {
2325+ if (auto favored = tryOptimizeGenericDisjunction (CS, Disjunction , Choices)) {
23152326 CS.favorConstraint (favored);
23162327 }
23172328
0 commit comments