@@ -2879,6 +2879,40 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const {
2879
2879
return std::nullopt;
2880
2880
}
2881
2881
2882
+ static bool shouldIgnoreHoleForCodeCompletion (ConstraintSystem &cs,
2883
+ TypeVariableType *typeVar,
2884
+ ConstraintLocator *srcLocator) {
2885
+ if (!cs.isForCodeCompletion ())
2886
+ return false ;
2887
+
2888
+ // Don't penalize solutions with unresolved generics.
2889
+ if (typeVar->getImpl ().getGenericParameter ())
2890
+ return true ;
2891
+
2892
+ // Don't penalize solutions if we couldn't determine the type of the code
2893
+ // completion token. We still want to examine the surrounding types in
2894
+ // that case.
2895
+ if (typeVar->getImpl ().isCodeCompletionToken ())
2896
+ return true ;
2897
+
2898
+ // Don't penalize solutions with holes due to missing arguments after the
2899
+ // code completion position.
2900
+ auto argLoc = srcLocator->findLast <LocatorPathElt::SynthesizedArgument>();
2901
+ if (argLoc && argLoc->isAfterCodeCompletionLoc ())
2902
+ return true ;
2903
+
2904
+ // Don't penalize solutions that have holes for ignored arguments.
2905
+ if (cs.hasArgumentsIgnoredForCodeCompletion ()) {
2906
+ // Avoid simplifying the locator if the constraint system didn't ignore
2907
+ // any arguments.
2908
+ auto argExpr = simplifyLocatorToAnchor (typeVar->getImpl ().getLocator ());
2909
+ if (cs.isArgumentIgnoredForCodeCompletion (argExpr.dyn_cast <Expr *>())) {
2910
+ return true ;
2911
+ }
2912
+ }
2913
+ return false ;
2914
+ }
2915
+
2882
2916
bool TypeVariableBinding::attempt (ConstraintSystem &cs) const {
2883
2917
auto type = Binding.BindingType ;
2884
2918
auto *srcLocator = Binding.getLocator ();
@@ -2934,33 +2968,9 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
2934
2968
}
2935
2969
2936
2970
auto reportHole = [&]() {
2937
- if (cs.isForCodeCompletion ()) {
2938
- // Don't penalize solutions with unresolved generics.
2939
- if (TypeVar->getImpl ().getGenericParameter ())
2940
- return false ;
2941
-
2942
- // Don't penalize solutions if we couldn't determine the type of the code
2943
- // completion token. We still want to examine the surrounding types in
2944
- // that case.
2945
- if (TypeVar->getImpl ().isCodeCompletionToken ())
2946
- return false ;
2947
-
2948
- // Don't penalize solutions with holes due to missing arguments after the
2949
- // code completion position.
2950
- auto argLoc = srcLocator->findLast <LocatorPathElt::SynthesizedArgument>();
2951
- if (argLoc && argLoc->isAfterCodeCompletionLoc ())
2952
- return false ;
2953
-
2954
- // Don't penalize solutions that have holes for ignored arguments.
2955
- if (cs.hasArgumentsIgnoredForCodeCompletion ()) {
2956
- // Avoid simplifying the locator if the constraint system didn't ignore
2957
- // any arguments.
2958
- auto argExpr = simplifyLocatorToAnchor (TypeVar->getImpl ().getLocator ());
2959
- if (cs.isArgumentIgnoredForCodeCompletion (argExpr.dyn_cast <Expr *>())) {
2960
- return false ;
2961
- }
2962
- }
2963
- }
2971
+ if (shouldIgnoreHoleForCodeCompletion (cs, TypeVar, srcLocator))
2972
+ return false ;
2973
+
2964
2974
// Reflect in the score that this type variable couldn't be
2965
2975
// resolved and had to be bound to a placeholder "hole" type.
2966
2976
cs.increaseScore (SK_Hole, srcLocator);
0 commit comments