File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -981,7 +981,15 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
981
981
++numHoles;
982
982
}
983
983
}
984
- CS.increaseScore (SK_Hole, Conjunction->getLocator (), numHoles);
984
+ // Increase the score for each hole we bind. Avoid doing this for
985
+ // completion since it's entirely expected we'll end up with
986
+ // ambiguities in the body of a closure if we're completing e.g
987
+ // `someOverloadedFn(#^CC^#)`. As such we don't want to penalize the
988
+ // solution for unbound type variables outside of the body since
989
+ // that will prevent us from being able to eagerly prune e.g
990
+ // disfavored overloads in the outer scope.
991
+ if (!CS.isForCodeCompletion ())
992
+ CS.increaseScore (SK_Hole, Conjunction->getLocator (), numHoles);
985
993
}
986
994
987
995
if (CS.worseThanBestSolution ())
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %batch-code-completion -debug-constraints 2> %t/constraints.log
3
+ // RUN: %FileCheck %s -check-prefix CONSTRAINTS < %t/constraints.log
4
+ // RUN: %FileCheck %s -check-prefix CONSTRAINTS-NOT < %t/constraints.log
5
+
6
+ protocol P1 { }
7
+ protocol P2 { }
8
+
9
+ func foo< T: P1 > ( _ fn: ( ) -> T ) { }
10
+
11
+ @_disfavoredOverload
12
+ func foo< T: P2 > ( _ fn: ( ) -> T ) { }
13
+
14
+ func bar( _ x: Int ) -> Int { }
15
+ func bar( _ x: String ) -> String { }
16
+
17
+ // Make sure we eagerly prune the disfavored overload of 'foo', despite the
18
+ // ambiguity in the closure body.
19
+ foo {
20
+ let x = bar ( #^COMPLETE^#)
21
+ // COMPLETE: Decl[FreeFunction]/CurrModule/Flair[ArgLabels]: ['(']{#(x): Int#}[')'][#Int#]; name=:
22
+ // COMPLETE: Decl[FreeFunction]/CurrModule/Flair[ArgLabels]: ['(']{#(x): String#}[')'][#String#]; name=:
23
+
24
+ return x
25
+ }
26
+
27
+ // CONSTRAINTS: attempting disjunction choice {{.*}}:12:6
28
+ // CONSTRAINTS: increasing 'disfavored overload' score
29
+ // CONSTRAINTS: solution is worse than the best solution
30
+
31
+ // CONSTRAINTS-NOT-NOT: increasing 'hole'
You can’t perform that action at this time.
0 commit comments