@@ -3101,16 +3101,16 @@ namespace {
31013101 DeclNameLoc nameLoc, bool implicit,
31023102 ConstraintLocator *ctorLocator,
31033103 SelectedOverload overload) {
3104+ auto locator = cs.getConstraintLocator (expr);
31043105 auto choice = overload.choice ;
31053106 assert (choice.getKind () != OverloadChoiceKind::DeclViaDynamic);
31063107 auto *ctor = cast<ConstructorDecl>(choice.getDecl ());
31073108
31083109 // If the subexpression is a metatype, build a direct reference to the
31093110 // constructor.
31103111 if (cs.getType (base)->is <AnyMetatypeType>()) {
3111- return buildMemberRef (
3112- base, dotLoc, overload, nameLoc, cs.getConstraintLocator (expr),
3113- ctorLocator, implicit, AccessSemantics::Ordinary);
3112+ return buildMemberRef (base, dotLoc, overload, nameLoc, locator,
3113+ ctorLocator, implicit, AccessSemantics::Ordinary);
31143114 }
31153115
31163116 // The subexpression must be either 'self' or 'super'.
@@ -3160,8 +3160,7 @@ namespace {
31603160 auto *call = new (cs.getASTContext ()) DotSyntaxCallExpr (ctorRef, dotLoc,
31613161 base);
31623162
3163- return finishApply (call, cs.getType (expr), cs.getConstraintLocator (expr),
3164- ctorLocator);
3163+ return finishApply (call, cs.getType (expr), locator, ctorLocator);
31653164 }
31663165
31673166 // / Give the deprecation warning for referring to a global function
@@ -4843,19 +4842,19 @@ namespace {
48434842 }
48444843
48454844 auto kind = origComponent.getKind ();
4846- auto locator = cs. getConstraintLocator (
4847- E, LocatorPathElt::KeyPathComponent (i));
4845+ auto componentLocator =
4846+ cs. getConstraintLocator ( E, LocatorPathElt::KeyPathComponent (i));
48484847
4849- // Adjust the locator such that it includes any additional elements to
4850- // point to the component's callee, e.g a SubscriptMember for a
4851- // subscript component.
4852- locator = cs.getCalleeLocator (locator );
4848+ // Get a locator such that it includes any additional elements to point
4849+ // to the component's callee, e.g a SubscriptMember for a subscript
4850+ // component.
4851+ auto calleeLoc = cs.getCalleeLocator (componentLocator );
48534852
48544853 bool isDynamicMember = false ;
48554854 // If this is an unresolved link, make sure we resolved it.
48564855 if (kind == KeyPathExpr::Component::Kind::UnresolvedProperty ||
48574856 kind == KeyPathExpr::Component::Kind::UnresolvedSubscript) {
4858- auto foundDecl = solution.getOverloadChoiceIfAvailable (locator );
4857+ auto foundDecl = solution.getOverloadChoiceIfAvailable (calleeLoc );
48594858 if (!foundDecl) {
48604859 // If we couldn't resolve the component, leave it alone.
48614860 resolvedComponents.push_back (origComponent);
@@ -4878,9 +4877,9 @@ namespace {
48784877
48794878 switch (kind) {
48804879 case KeyPathExpr::Component::Kind::UnresolvedProperty: {
4881- buildKeyPathPropertyComponent (solution.getOverloadChoice (locator ),
4882- origComponent.getLoc (),
4883- locator, resolvedComponents);
4880+ buildKeyPathPropertyComponent (solution.getOverloadChoice (calleeLoc ),
4881+ origComponent.getLoc (), calleeLoc,
4882+ resolvedComponents);
48844883 break ;
48854884 }
48864885 case KeyPathExpr::Component::Kind::UnresolvedSubscript: {
@@ -4889,9 +4888,9 @@ namespace {
48894888 subscriptLabels = origComponent.getSubscriptLabels ();
48904889
48914890 buildKeyPathSubscriptComponent (
4892- solution.getOverloadChoice (locator ),
4893- origComponent.getLoc (), origComponent. getIndexExpr () ,
4894- subscriptLabels, locator, resolvedComponents);
4891+ solution.getOverloadChoice (calleeLoc), origComponent. getLoc ( ),
4892+ origComponent.getIndexExpr (), subscriptLabels, componentLocator ,
4893+ resolvedComponents);
48954894 break ;
48964895 }
48974896 case KeyPathExpr::Component::Kind::OptionalChain: {
@@ -5140,9 +5139,10 @@ namespace {
51405139 SmallVectorImpl<KeyPathExpr::Component> &components) {
51415140 auto subscript = cast<SubscriptDecl>(overload.choice .getDecl ());
51425141 assert (!subscript->isGetterMutating ());
5142+ auto memberLoc = cs.getCalleeLocator (locator);
51435143
51445144 // Compute substitutions to refer to the member.
5145- auto ref = resolveConcreteDeclRef (subscript, locator );
5145+ auto ref = resolveConcreteDeclRef (subscript, memberLoc );
51465146
51475147 // If this is a @dynamicMemberLookup reference to resolve a property
51485148 // through the subscript(dynamicMember:) member, restore the
@@ -5161,23 +5161,27 @@ namespace {
51615161 if (overload.choice .getKind () ==
51625162 OverloadChoiceKind::KeyPathDynamicMemberLookup) {
51635163 indexExpr = buildKeyPathDynamicMemberIndexExpr (
5164- indexType->castTo <BoundGenericType>(), componentLoc, locator );
5164+ indexType->castTo <BoundGenericType>(), componentLoc, memberLoc );
51655165 } else {
51665166 auto fieldName = overload.choice .getName ().getBaseIdentifier ().str ();
51675167 indexExpr = buildDynamicMemberLookupIndexExpr (fieldName, componentLoc,
51685168 indexType);
51695169 }
5170+ // Record the implicit subscript expr's parameter bindings and matching
5171+ // direction as `coerceCallArguments` requires them.
5172+ solution.recordSingleArgMatchingChoice (locator);
51705173 }
51715174
51725175 auto subscriptType =
51735176 simplifyType (overload.openedType )->castTo <AnyFunctionType>();
51745177 auto resolvedTy = subscriptType->getResult ();
51755178
51765179 // Coerce the indices to the type the subscript expects.
5177- auto *newIndexExpr =
5178- coerceCallArguments (indexExpr, subscriptType, ref,
5179- /* applyExpr*/ nullptr , labels,
5180- locator, /* appliedPropertyWrappers*/ {});
5180+ auto *newIndexExpr = coerceCallArguments (
5181+ indexExpr, subscriptType, ref,
5182+ /* applyExpr*/ nullptr , labels,
5183+ cs.getConstraintLocator (locator, ConstraintLocator::ApplyArgument),
5184+ /* appliedPropertyWrappers*/ {});
51815185
51825186 // We need to be able to hash the captured index values in order for
51835187 // KeyPath itself to be hashable, so check that all of the subscript
@@ -5763,6 +5767,8 @@ Expr *ExprRewriter::coerceCallArguments(
57635767 ArrayRef<Identifier> argLabels,
57645768 ConstraintLocatorBuilder locator,
57655769 ArrayRef<AppliedPropertyWrapper> appliedPropertyWrappers) {
5770+ assert (locator.last () && locator.last ()->is <LocatorPathElt::ApplyArgument>());
5771+
57665772 auto &ctx = getConstraintSystem ().getASTContext ();
57675773 auto params = funcType->getParams ();
57685774 unsigned appliedWrapperIndex = 0 ;
@@ -5775,11 +5781,6 @@ Expr *ExprRewriter::coerceCallArguments(
57755781 LocatorPathElt::ApplyArgToParam (argIdx, paramIdx, flags));
57765782 };
57775783
5778- bool matchCanFail =
5779- llvm::any_of (params, [](const AnyFunctionType::Param ¶m) {
5780- return param.getPlainType ()->hasUnresolvedType ();
5781- });
5782-
57835784 // Determine whether this application has curried self.
57845785 bool skipCurriedSelf = apply ? hasCurriedSelf (cs, callee, apply) : true ;
57855786 // Determine the parameter bindings.
@@ -5814,34 +5815,14 @@ Expr *ExprRewriter::coerceCallArguments(
58145815 // Apply labels to arguments.
58155816 AnyFunctionType::relabelParams (args, argLabels);
58165817
5817- MatchCallArgumentListener listener;
58185818 auto unlabeledTrailingClosureIndex =
58195819 arg->getUnlabeledTrailingClosureIndexOfPackedArgument ();
58205820
5821- // Determine the trailing closure matching rule that was applied. This
5822- // is only relevant for explicit calls and subscripts.
5823- auto trailingClosureMatching = TrailingClosureMatching::Forward;
5824- {
5825- SmallVector<LocatorPathElt, 4 > path;
5826- auto anchor = locator.getLocatorParts (path);
5827- if (!path.empty () && path.back ().is <LocatorPathElt::ApplyArgument>() &&
5828- !anchor.isExpr (ExprKind::UnresolvedDot)) {
5829- auto locatorPtr = cs.getConstraintLocator (locator);
5830- assert (solution.trailingClosureMatchingChoices .count (locatorPtr) == 1 );
5831- trailingClosureMatching = solution.trailingClosureMatchingChoices .find (
5832- locatorPtr)->second ;
5833- }
5834- }
5835-
5836- auto callArgumentMatch = constraints::matchCallArguments (
5837- args, params, paramInfo, unlabeledTrailingClosureIndex,
5838- /* allowFixes=*/ false , listener, trailingClosureMatching);
5839-
5840- assert ((matchCanFail || callArgumentMatch) &&
5841- " Call arguments did not match up?" );
5842- (void )matchCanFail;
5843-
5844- auto parameterBindings = std::move (callArgumentMatch->parameterBindings );
5821+ // Determine the parameter bindings that were applied.
5822+ auto *locatorPtr = cs.getConstraintLocator (locator);
5823+ assert (solution.argumentMatchingChoices .count (locatorPtr) == 1 );
5824+ auto parameterBindings = solution.argumentMatchingChoices .find (locatorPtr)
5825+ ->second .parameterBindings ;
58455826
58465827 // We should either have parentheses or a tuple.
58475828 auto *argTuple = dyn_cast<TupleExpr>(arg);
@@ -6851,12 +6832,11 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
68516832 ConstraintLocator::ConstructorMember}));
68526833
68536834 solution.overloadChoices .insert ({memberLoc, overload});
6854- solution.trailingClosureMatchingChoices .insert (
6855- {cs.getConstraintLocator (callLocator,
6856- ConstraintLocator::ApplyArgument),
6857- TrailingClosureMatching::Forward});
68586835 }
68596836
6837+ // Record the implicit call's parameter bindings and match direction.
6838+ solution.recordSingleArgMatchingChoice (callLocator);
6839+
68606840 finishApply (implicitInit, toType, callLocator, callLocator);
68616841 return implicitInit;
68626842 }
0 commit comments