@@ -3099,16 +3099,16 @@ namespace {
30993099 DeclNameLoc nameLoc, bool implicit,
31003100 ConstraintLocator *ctorLocator,
31013101 SelectedOverload overload) {
3102+ auto locator = cs.getConstraintLocator (expr);
31023103 auto choice = overload.choice ;
31033104 assert (choice.getKind () != OverloadChoiceKind::DeclViaDynamic);
31043105 auto *ctor = cast<ConstructorDecl>(choice.getDecl ());
31053106
31063107 // If the subexpression is a metatype, build a direct reference to the
31073108 // constructor.
31083109 if (cs.getType (base)->is <AnyMetatypeType>()) {
3109- return buildMemberRef (
3110- base, dotLoc, overload, nameLoc, cs.getConstraintLocator (expr),
3111- ctorLocator, implicit, AccessSemantics::Ordinary);
3110+ return buildMemberRef (base, dotLoc, overload, nameLoc, locator,
3111+ ctorLocator, implicit, AccessSemantics::Ordinary);
31123112 }
31133113
31143114 // The subexpression must be either 'self' or 'super'.
@@ -3158,8 +3158,7 @@ namespace {
31583158 auto *call = new (cs.getASTContext ()) DotSyntaxCallExpr (ctorRef, dotLoc,
31593159 base);
31603160
3161- return finishApply (call, cs.getType (expr), cs.getConstraintLocator (expr),
3162- ctorLocator);
3161+ return finishApply (call, cs.getType (expr), locator, ctorLocator);
31633162 }
31643163
31653164 // / Give the deprecation warning for referring to a global function
@@ -4841,19 +4840,19 @@ namespace {
48414840 }
48424841
48434842 auto kind = origComponent.getKind ();
4844- auto locator = cs. getConstraintLocator (
4845- E, LocatorPathElt::KeyPathComponent (i));
4843+ auto componentLocator =
4844+ cs. getConstraintLocator ( E, LocatorPathElt::KeyPathComponent (i));
48464845
4847- // Adjust the locator such that it includes any additional elements to
4848- // point to the component's callee, e.g a SubscriptMember for a
4849- // subscript component.
4850- locator = cs.getCalleeLocator (locator );
4846+ // Get a locator such that it includes any additional elements to point
4847+ // to the component's callee, e.g a SubscriptMember for a subscript
4848+ // component.
4849+ auto calleeLoc = cs.getCalleeLocator (componentLocator );
48514850
48524851 bool isDynamicMember = false ;
48534852 // If this is an unresolved link, make sure we resolved it.
48544853 if (kind == KeyPathExpr::Component::Kind::UnresolvedProperty ||
48554854 kind == KeyPathExpr::Component::Kind::UnresolvedSubscript) {
4856- auto foundDecl = solution.getOverloadChoiceIfAvailable (locator );
4855+ auto foundDecl = solution.getOverloadChoiceIfAvailable (calleeLoc );
48574856 if (!foundDecl) {
48584857 // If we couldn't resolve the component, leave it alone.
48594858 resolvedComponents.push_back (origComponent);
@@ -4876,9 +4875,9 @@ namespace {
48764875
48774876 switch (kind) {
48784877 case KeyPathExpr::Component::Kind::UnresolvedProperty: {
4879- buildKeyPathPropertyComponent (solution.getOverloadChoice (locator ),
4880- origComponent.getLoc (),
4881- locator, resolvedComponents);
4878+ buildKeyPathPropertyComponent (solution.getOverloadChoice (calleeLoc ),
4879+ origComponent.getLoc (), calleeLoc,
4880+ resolvedComponents);
48824881 break ;
48834882 }
48844883 case KeyPathExpr::Component::Kind::UnresolvedSubscript: {
@@ -4887,9 +4886,9 @@ namespace {
48874886 subscriptLabels = origComponent.getSubscriptLabels ();
48884887
48894888 buildKeyPathSubscriptComponent (
4890- solution.getOverloadChoice (locator ),
4891- origComponent.getLoc (), origComponent. getIndexExpr () ,
4892- subscriptLabels, locator, resolvedComponents);
4889+ solution.getOverloadChoice (calleeLoc), origComponent. getLoc ( ),
4890+ origComponent.getIndexExpr (), subscriptLabels, componentLocator ,
4891+ resolvedComponents);
48934892 break ;
48944893 }
48954894 case KeyPathExpr::Component::Kind::OptionalChain: {
@@ -5138,9 +5137,10 @@ namespace {
51385137 SmallVectorImpl<KeyPathExpr::Component> &components) {
51395138 auto subscript = cast<SubscriptDecl>(overload.choice .getDecl ());
51405139 assert (!subscript->isGetterMutating ());
5140+ auto memberLoc = cs.getCalleeLocator (locator);
51415141
51425142 // Compute substitutions to refer to the member.
5143- auto ref = resolveConcreteDeclRef (subscript, locator );
5143+ auto ref = resolveConcreteDeclRef (subscript, memberLoc );
51445144
51455145 // If this is a @dynamicMemberLookup reference to resolve a property
51465146 // through the subscript(dynamicMember:) member, restore the
@@ -5159,23 +5159,27 @@ namespace {
51595159 if (overload.choice .getKind () ==
51605160 OverloadChoiceKind::KeyPathDynamicMemberLookup) {
51615161 indexExpr = buildKeyPathDynamicMemberIndexExpr (
5162- indexType->castTo <BoundGenericType>(), componentLoc, locator );
5162+ indexType->castTo <BoundGenericType>(), componentLoc, memberLoc );
51635163 } else {
51645164 auto fieldName = overload.choice .getName ().getBaseIdentifier ().str ();
51655165 indexExpr = buildDynamicMemberLookupIndexExpr (fieldName, componentLoc,
51665166 indexType);
51675167 }
5168+ // Record the implicit subscript expr's parameter bindings and matching
5169+ // direction as `coerceCallArguments` requires them.
5170+ solution.recordSingleArgMatchingChoice (locator);
51685171 }
51695172
51705173 auto subscriptType =
51715174 simplifyType (overload.openedType )->castTo <AnyFunctionType>();
51725175 auto resolvedTy = subscriptType->getResult ();
51735176
51745177 // Coerce the indices to the type the subscript expects.
5175- auto *newIndexExpr =
5176- coerceCallArguments (indexExpr, subscriptType, ref,
5177- /* applyExpr*/ nullptr , labels,
5178- locator, /* appliedPropertyWrappers*/ {});
5178+ auto *newIndexExpr = coerceCallArguments (
5179+ indexExpr, subscriptType, ref,
5180+ /* applyExpr*/ nullptr , labels,
5181+ cs.getConstraintLocator (locator, ConstraintLocator::ApplyArgument),
5182+ /* appliedPropertyWrappers*/ {});
51795183
51805184 // We need to be able to hash the captured index values in order for
51815185 // KeyPath itself to be hashable, so check that all of the subscript
@@ -5761,6 +5765,8 @@ Expr *ExprRewriter::coerceCallArguments(
57615765 ArrayRef<Identifier> argLabels,
57625766 ConstraintLocatorBuilder locator,
57635767 ArrayRef<AppliedPropertyWrapper> appliedPropertyWrappers) {
5768+ assert (locator.last () && locator.last ()->is <LocatorPathElt::ApplyArgument>());
5769+
57645770 auto &ctx = getConstraintSystem ().getASTContext ();
57655771 auto params = funcType->getParams ();
57665772 unsigned appliedWrapperIndex = 0 ;
@@ -5773,11 +5779,6 @@ Expr *ExprRewriter::coerceCallArguments(
57735779 LocatorPathElt::ApplyArgToParam (argIdx, paramIdx, flags));
57745780 };
57755781
5776- bool matchCanFail =
5777- llvm::any_of (params, [](const AnyFunctionType::Param ¶m) {
5778- return param.getPlainType ()->hasUnresolvedType ();
5779- });
5780-
57815782 // Determine whether this application has curried self.
57825783 bool skipCurriedSelf = apply ? hasCurriedSelf (cs, callee, apply) : true ;
57835784 // Determine the parameter bindings.
@@ -5812,34 +5813,14 @@ Expr *ExprRewriter::coerceCallArguments(
58125813 // Apply labels to arguments.
58135814 AnyFunctionType::relabelParams (args, argLabels);
58145815
5815- MatchCallArgumentListener listener;
58165816 auto unlabeledTrailingClosureIndex =
58175817 arg->getUnlabeledTrailingClosureIndexOfPackedArgument ();
58185818
5819- // Determine the trailing closure matching rule that was applied. This
5820- // is only relevant for explicit calls and subscripts.
5821- auto trailingClosureMatching = TrailingClosureMatching::Forward;
5822- {
5823- SmallVector<LocatorPathElt, 4 > path;
5824- auto anchor = locator.getLocatorParts (path);
5825- if (!path.empty () && path.back ().is <LocatorPathElt::ApplyArgument>() &&
5826- !anchor.isExpr (ExprKind::UnresolvedDot)) {
5827- auto locatorPtr = cs.getConstraintLocator (locator);
5828- assert (solution.trailingClosureMatchingChoices .count (locatorPtr) == 1 );
5829- trailingClosureMatching = solution.trailingClosureMatchingChoices .find (
5830- locatorPtr)->second ;
5831- }
5832- }
5833-
5834- auto callArgumentMatch = constraints::matchCallArguments (
5835- args, params, paramInfo, unlabeledTrailingClosureIndex,
5836- /* allowFixes=*/ false , listener, trailingClosureMatching);
5837-
5838- assert ((matchCanFail || callArgumentMatch) &&
5839- " Call arguments did not match up?" );
5840- (void )matchCanFail;
5841-
5842- auto parameterBindings = std::move (callArgumentMatch->parameterBindings );
5819+ // Determine the parameter bindings that were applied.
5820+ auto *locatorPtr = cs.getConstraintLocator (locator);
5821+ assert (solution.argumentMatchingChoices .count (locatorPtr) == 1 );
5822+ auto parameterBindings = solution.argumentMatchingChoices .find (locatorPtr)
5823+ ->second .parameterBindings ;
58435824
58445825 // We should either have parentheses or a tuple.
58455826 auto *argTuple = dyn_cast<TupleExpr>(arg);
@@ -6849,12 +6830,11 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
68496830 ConstraintLocator::ConstructorMember}));
68506831
68516832 solution.overloadChoices .insert ({memberLoc, overload});
6852- solution.trailingClosureMatchingChoices .insert (
6853- {cs.getConstraintLocator (callLocator,
6854- ConstraintLocator::ApplyArgument),
6855- TrailingClosureMatching::Forward});
68566833 }
68576834
6835+ // Record the implicit call's parameter bindings and match direction.
6836+ solution.recordSingleArgMatchingChoice (callLocator);
6837+
68586838 finishApply (implicitInit, toType, callLocator, callLocator);
68596839 return implicitInit;
68606840 }
0 commit comments