@@ -764,58 +764,6 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
764
764
return listener.relabelArguments (actualArgNames);
765
765
}
766
766
767
- // / Find the callee declaration and uncurry level for a given call
768
- // / locator.
769
- static std::tuple<ValueDecl *, bool , ArrayRef<Identifier>, bool ,
770
- ConstraintLocator *>
771
- getCalleeDeclAndArgs (ConstraintSystem &cs,
772
- ConstraintLocatorBuilder callBuilder) {
773
- auto formUnknownCallee =
774
- []() -> std::tuple<ValueDecl *, bool , ArrayRef<Identifier>, bool ,
775
- ConstraintLocator *> {
776
- return std::make_tuple (/* decl*/ nullptr , /* hasAppliedSelf*/ false ,
777
- /* argLabels*/ ArrayRef<Identifier>(),
778
- /* hasTrailingClosure*/ false ,
779
- /* calleeLocator*/ nullptr );
780
- };
781
-
782
- auto *callLocator = cs.getConstraintLocator (callBuilder);
783
- auto *callExpr = callLocator->getAnchor ();
784
-
785
- // Break down the call.
786
- if (!callExpr)
787
- return formUnknownCallee ();
788
-
789
- // Our remaining path can only be 'ApplyArgument'.
790
- auto path = callLocator->getPath ();
791
- if (!path.empty () && !path.back ().is <LocatorPathElt::ApplyArgument>())
792
- return formUnknownCallee ();
793
-
794
- // Dig out the callee information.
795
- auto argInfo = cs.getArgumentInfo (callLocator);
796
- if (!argInfo)
797
- return formUnknownCallee ();
798
-
799
- auto argLabels = argInfo->Labels ;
800
- auto hasTrailingClosure = argInfo->HasTrailingClosure ;
801
- auto calleeLocator = cs.getCalleeLocator (callLocator);
802
-
803
- // Find the overload choice corresponding to the callee locator.
804
- auto selectedOverload = cs.findSelectedOverloadFor (calleeLocator);
805
-
806
- // If we didn't find any matching overloads, we're done. Just return the
807
- // argument info.
808
- if (!selectedOverload)
809
- return std::make_tuple (/* decl*/ nullptr , /* hasAppliedSelf*/ false ,
810
- argLabels, hasTrailingClosure,
811
- /* calleeLocator*/ nullptr );
812
-
813
- // Return the found declaration, assuming there is one.
814
- auto choice = selectedOverload->choice ;
815
- return std::make_tuple (choice.getDeclOrNull (), hasAppliedSelf (cs, choice),
816
- argLabels, hasTrailingClosure, calleeLocator);
817
- }
818
-
819
767
class ArgumentFailureTracker : public MatchCallArgumentListener {
820
768
ConstraintSystem &CS;
821
769
SmallVectorImpl<AnyFunctionType::Param> &Arguments;
@@ -1002,22 +950,29 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
1002
950
ArrayRef<AnyFunctionType::Param> args,
1003
951
ArrayRef<AnyFunctionType::Param> params, ConstraintKind subKind,
1004
952
ConstraintLocatorBuilder locator) {
1005
- // Extract the parameters.
1006
- ValueDecl *callee;
1007
- bool hasAppliedSelf;
1008
- ArrayRef<Identifier> argLabels;
1009
- bool hasTrailingClosure = false ;
1010
- ConstraintLocator *calleeLocator;
1011
- std::tie (callee, hasAppliedSelf, argLabels, hasTrailingClosure,
1012
- calleeLocator) =
1013
- getCalleeDeclAndArgs (cs, locator);
1014
-
1015
- ParameterListInfo paramInfo (params, callee, hasAppliedSelf);
953
+ auto *loc = cs.getConstraintLocator (locator);
954
+ assert (loc->isLastElement <LocatorPathElt::ApplyArgument>());
955
+
956
+ ValueDecl *callee = nullptr ;
957
+ bool appliedSelf = false ;
958
+
959
+ // Resolve the callee for the application.
960
+ auto *calleeLocator = cs.getCalleeLocator (loc);
961
+ if (auto overload = cs.findSelectedOverloadFor (calleeLocator)) {
962
+ callee = overload->choice .getDeclOrNull ();
963
+ appliedSelf = hasAppliedSelf (cs, overload->choice );
964
+ }
965
+
966
+ ParameterListInfo paramInfo (params, callee, appliedSelf);
967
+
968
+ // Dig out the argument information.
969
+ auto argInfo = cs.getArgumentInfo (loc);
970
+ assert (argInfo);
1016
971
1017
972
// Apply labels to arguments.
1018
973
SmallVector<AnyFunctionType::Param, 8 > argsWithLabels;
1019
974
argsWithLabels.append (args.begin (), args.end ());
1020
- AnyFunctionType::relabelParams (argsWithLabels, argLabels );
975
+ AnyFunctionType::relabelParams (argsWithLabels, argInfo-> Labels );
1021
976
1022
977
// Special case when a single tuple argument if used
1023
978
// instead of N distinct arguments e.g.:
@@ -1059,7 +1014,7 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
1059
1014
ArgumentFailureTracker listener (cs, argsWithLabels, params,
1060
1015
parameterBindings, locator);
1061
1016
if (constraints::matchCallArguments (
1062
- argsWithLabels, params, paramInfo, hasTrailingClosure ,
1017
+ argsWithLabels, params, paramInfo, argInfo-> HasTrailingClosure ,
1063
1018
cs.shouldAttemptFixes (), listener, parameterBindings))
1064
1019
return cs.getTypeMatchFailure (locator);
1065
1020
0 commit comments