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