@@ -123,10 +123,9 @@ bool constraints::doesMemberRefApplyCurriedSelf(Type baseTy,
123
123
return true ;
124
124
}
125
125
126
- static bool
127
- areConservativelyCompatibleArgumentLabels (OverloadChoice choice,
128
- ArrayRef<FunctionType::Param> args,
129
- bool hasTrailingClosure) {
126
+ static bool areConservativelyCompatibleArgumentLabels (
127
+ OverloadChoice choice, SmallVectorImpl<FunctionType::Param> &args,
128
+ bool hasTrailingClosure) {
130
129
ValueDecl *decl = nullptr ;
131
130
switch (choice.getKind ()) {
132
131
case OverloadChoiceKind::Decl:
@@ -217,7 +216,7 @@ static bool acceptsTrailingClosure(const AnyFunctionType::Param ¶m) {
217
216
// FIXME: This should return ConstraintSystem::TypeMatchResult instead
218
217
// to give more information to the solver about the failure.
219
218
bool constraints::
220
- matchCallArguments (ArrayRef <AnyFunctionType::Param> args,
219
+ matchCallArguments (SmallVectorImpl <AnyFunctionType::Param> & args,
221
220
ArrayRef<AnyFunctionType::Param> params,
222
221
const ParameterListInfo ¶mInfo,
223
222
bool hasTrailingClosure,
@@ -571,8 +570,6 @@ matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
571
570
if (listener.extraArgument (index))
572
571
return true ;
573
572
}
574
-
575
- return false ;
576
573
}
577
574
578
575
// FIXME: If we had the actual parameters and knew the body names, those
@@ -582,7 +579,6 @@ matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
582
579
583
580
// If we have any unfulfilled parameters, check them now.
584
581
if (haveUnfulfilledParams) {
585
- bool hasSynthesizedArgs = false ;
586
582
for (paramIdx = 0 ; paramIdx != numParams; ++paramIdx) {
587
583
// If we have a binding for this parameter, we're done.
588
584
if (!parameterBindings[paramIdx].empty ())
@@ -600,17 +596,11 @@ matchCallArguments(ArrayRef<AnyFunctionType::Param> args,
600
596
601
597
if (auto newArgIdx = listener.missingArgument (paramIdx)) {
602
598
parameterBindings[paramIdx].push_back (*newArgIdx);
603
- hasSynthesizedArgs = true ;
604
599
continue ;
605
600
}
606
601
607
602
return true ;
608
603
}
609
-
610
- // If all of the missing arguments have been synthesized,
611
- // let's stop since we have found the problem.
612
- if (hasSynthesizedArgs)
613
- return false ;
614
604
}
615
605
616
606
// If any arguments were provided out-of-order, check whether we have
@@ -873,6 +863,15 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
873
863
874
864
bool outOfOrderArgument (unsigned argIdx, unsigned prevArgIdx) override {
875
865
if (CS.shouldAttemptFixes ()) {
866
+ // If some of the arguments are missing/extraneous, no reason to
867
+ // record a fix for this, increase the score so there is a way
868
+ // to identify that there is something going on besides just missing
869
+ // arguments.
870
+ if (NumSynthesizedArgs || !ExtraArguments.empty ()) {
871
+ CS.increaseScore (SK_Fix);
872
+ return false ;
873
+ }
874
+
876
875
auto *fix = MoveOutOfOrderArgument::create (
877
876
CS, argIdx, prevArgIdx, Bindings, CS.getConstraintLocator (Locator));
878
877
return CS.recordFix (fix);
@@ -885,31 +884,42 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
885
884
if (!CS.shouldAttemptFixes ())
886
885
return true ;
887
886
887
+ // TODO(diagnostics): If re-labeling is mixed with extra arguments,
888
+ // let's produce a fix only for extraneous arguments for now,
889
+ // because they'd share a locator path which (currently) means
890
+ // one fix would overwrite another.
891
+ if (!ExtraArguments.empty ()) {
892
+ CS.increaseScore (SK_Fix);
893
+ return false ;
894
+ }
895
+
888
896
auto *anchor = Locator.getBaseLocator ()->getAnchor ();
889
- if (!anchor)
897
+ if (!anchor || Arguments. size () != newLabels. size () )
890
898
return true ;
891
899
892
900
unsigned numExtraneous = 0 ;
893
- for (unsigned paramIdx = 0 , n = Bindings.size (); paramIdx != n;
894
- ++paramIdx) {
895
- if (Bindings[paramIdx].empty ())
901
+ unsigned numRenames = 0 ;
902
+ for (unsigned i : indices (newLabels)) {
903
+ auto argLabel = Arguments[i].getLabel ();
904
+ auto paramLabel = newLabels[i];
905
+
906
+ if (argLabel == paramLabel)
896
907
continue ;
897
908
898
- const auto paramLabel = Parameters[paramIdx].getLabel ();
899
- for (auto argIdx : Bindings[paramIdx]) {
900
- auto argLabel = Arguments[argIdx].getLabel ();
901
- if (paramLabel.empty () && !argLabel.empty ())
909
+ if (!argLabel.empty ()) {
910
+ if (paramLabel.empty ())
902
911
++numExtraneous;
912
+ else
913
+ ++numRenames;
903
914
}
904
915
}
905
916
906
917
auto *locator = CS.getConstraintLocator (Locator);
907
918
auto *fix = RelabelArguments::create (CS, newLabels, locator);
908
- CS.recordFix (fix);
909
- // Re-labeling fixes with extraneous labels should take
910
- // lower priority vs. other fixes on same/different
911
- // overload(s) where labels did line up correctly.
912
- CS.increaseScore (ScoreKind::SK_Fix, numExtraneous);
919
+ // Re-labeling fixes with extraneous/incorrect labels should be
920
+ // lower priority vs. other fixes on same/different overload(s)
921
+ // where labels did line up correctly.
922
+ CS.recordFix (fix, /* impact=*/ 1 + numExtraneous * 2 + numRenames * 3 );
913
923
return false ;
914
924
}
915
925
0 commit comments