@@ -3101,16 +3101,16 @@ namespace {
3101
3101
DeclNameLoc nameLoc, bool implicit,
3102
3102
ConstraintLocator *ctorLocator,
3103
3103
SelectedOverload overload) {
3104
+ auto locator = cs.getConstraintLocator (expr);
3104
3105
auto choice = overload.choice ;
3105
3106
assert (choice.getKind () != OverloadChoiceKind::DeclViaDynamic);
3106
3107
auto *ctor = cast<ConstructorDecl>(choice.getDecl ());
3107
3108
3108
3109
// If the subexpression is a metatype, build a direct reference to the
3109
3110
// constructor.
3110
3111
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);
3114
3114
}
3115
3115
3116
3116
// The subexpression must be either 'self' or 'super'.
@@ -3160,8 +3160,7 @@ namespace {
3160
3160
auto *call = new (cs.getASTContext ()) DotSyntaxCallExpr (ctorRef, dotLoc,
3161
3161
base);
3162
3162
3163
- return finishApply (call, cs.getType (expr), cs.getConstraintLocator (expr),
3164
- ctorLocator);
3163
+ return finishApply (call, cs.getType (expr), locator, ctorLocator);
3165
3164
}
3166
3165
3167
3166
// / Give the deprecation warning for referring to a global function
@@ -4843,19 +4842,19 @@ namespace {
4843
4842
}
4844
4843
4845
4844
auto kind = origComponent.getKind ();
4846
- auto locator = cs. getConstraintLocator (
4847
- E, LocatorPathElt::KeyPathComponent (i));
4845
+ auto componentLocator =
4846
+ cs. getConstraintLocator ( E, LocatorPathElt::KeyPathComponent (i));
4848
4847
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 );
4853
4852
4854
4853
bool isDynamicMember = false ;
4855
4854
// If this is an unresolved link, make sure we resolved it.
4856
4855
if (kind == KeyPathExpr::Component::Kind::UnresolvedProperty ||
4857
4856
kind == KeyPathExpr::Component::Kind::UnresolvedSubscript) {
4858
- auto foundDecl = solution.getOverloadChoiceIfAvailable (locator );
4857
+ auto foundDecl = solution.getOverloadChoiceIfAvailable (calleeLoc );
4859
4858
if (!foundDecl) {
4860
4859
// If we couldn't resolve the component, leave it alone.
4861
4860
resolvedComponents.push_back (origComponent);
@@ -4878,9 +4877,9 @@ namespace {
4878
4877
4879
4878
switch (kind) {
4880
4879
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);
4884
4883
break ;
4885
4884
}
4886
4885
case KeyPathExpr::Component::Kind::UnresolvedSubscript: {
@@ -4889,9 +4888,9 @@ namespace {
4889
4888
subscriptLabels = origComponent.getSubscriptLabels ();
4890
4889
4891
4890
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);
4895
4894
break ;
4896
4895
}
4897
4896
case KeyPathExpr::Component::Kind::OptionalChain: {
@@ -5140,9 +5139,10 @@ namespace {
5140
5139
SmallVectorImpl<KeyPathExpr::Component> &components) {
5141
5140
auto subscript = cast<SubscriptDecl>(overload.choice .getDecl ());
5142
5141
assert (!subscript->isGetterMutating ());
5142
+ auto memberLoc = cs.getCalleeLocator (locator);
5143
5143
5144
5144
// Compute substitutions to refer to the member.
5145
- auto ref = resolveConcreteDeclRef (subscript, locator );
5145
+ auto ref = resolveConcreteDeclRef (subscript, memberLoc );
5146
5146
5147
5147
// If this is a @dynamicMemberLookup reference to resolve a property
5148
5148
// through the subscript(dynamicMember:) member, restore the
@@ -5161,23 +5161,27 @@ namespace {
5161
5161
if (overload.choice .getKind () ==
5162
5162
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
5163
5163
indexExpr = buildKeyPathDynamicMemberIndexExpr (
5164
- indexType->castTo <BoundGenericType>(), componentLoc, locator );
5164
+ indexType->castTo <BoundGenericType>(), componentLoc, memberLoc );
5165
5165
} else {
5166
5166
auto fieldName = overload.choice .getName ().getBaseIdentifier ().str ();
5167
5167
indexExpr = buildDynamicMemberLookupIndexExpr (fieldName, componentLoc,
5168
5168
indexType);
5169
5169
}
5170
+ // Record the implicit subscript expr's parameter bindings and matching
5171
+ // direction as `coerceCallArguments` requires them.
5172
+ solution.recordSingleArgMatchingChoice (locator);
5170
5173
}
5171
5174
5172
5175
auto subscriptType =
5173
5176
simplifyType (overload.openedType )->castTo <AnyFunctionType>();
5174
5177
auto resolvedTy = subscriptType->getResult ();
5175
5178
5176
5179
// 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*/ {});
5181
5185
5182
5186
// We need to be able to hash the captured index values in order for
5183
5187
// KeyPath itself to be hashable, so check that all of the subscript
@@ -5763,6 +5767,8 @@ Expr *ExprRewriter::coerceCallArguments(
5763
5767
ArrayRef<Identifier> argLabels,
5764
5768
ConstraintLocatorBuilder locator,
5765
5769
ArrayRef<AppliedPropertyWrapper> appliedPropertyWrappers) {
5770
+ assert (locator.last () && locator.last ()->is <LocatorPathElt::ApplyArgument>());
5771
+
5766
5772
auto &ctx = getConstraintSystem ().getASTContext ();
5767
5773
auto params = funcType->getParams ();
5768
5774
unsigned appliedWrapperIndex = 0 ;
@@ -5775,11 +5781,6 @@ Expr *ExprRewriter::coerceCallArguments(
5775
5781
LocatorPathElt::ApplyArgToParam (argIdx, paramIdx, flags));
5776
5782
};
5777
5783
5778
- bool matchCanFail =
5779
- llvm::any_of (params, [](const AnyFunctionType::Param ¶m) {
5780
- return param.getPlainType ()->hasUnresolvedType ();
5781
- });
5782
-
5783
5784
// Determine whether this application has curried self.
5784
5785
bool skipCurriedSelf = apply ? hasCurriedSelf (cs, callee, apply) : true ;
5785
5786
// Determine the parameter bindings.
@@ -5814,34 +5815,14 @@ Expr *ExprRewriter::coerceCallArguments(
5814
5815
// Apply labels to arguments.
5815
5816
AnyFunctionType::relabelParams (args, argLabels);
5816
5817
5817
- MatchCallArgumentListener listener;
5818
5818
auto unlabeledTrailingClosureIndex =
5819
5819
arg->getUnlabeledTrailingClosureIndexOfPackedArgument ();
5820
5820
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 ;
5845
5826
5846
5827
// We should either have parentheses or a tuple.
5847
5828
auto *argTuple = dyn_cast<TupleExpr>(arg);
@@ -6851,12 +6832,11 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
6851
6832
ConstraintLocator::ConstructorMember}));
6852
6833
6853
6834
solution.overloadChoices .insert ({memberLoc, overload});
6854
- solution.trailingClosureMatchingChoices .insert (
6855
- {cs.getConstraintLocator (callLocator,
6856
- ConstraintLocator::ApplyArgument),
6857
- TrailingClosureMatching::Forward});
6858
6835
}
6859
6836
6837
+ // Record the implicit call's parameter bindings and match direction.
6838
+ solution.recordSingleArgMatchingChoice (callLocator);
6839
+
6860
6840
finishApply (implicitInit, toType, callLocator, callLocator);
6861
6841
return implicitInit;
6862
6842
}
0 commit comments