@@ -2439,38 +2439,12 @@ void ConstraintSystem::bindOverloadType(const SelectedOverload &overload,
24392439 // don't which at the moment, so let's allow its type to be l-value.
24402440 auto memberTy = createTypeVariable (keyPathLoc, TVO_CanBindToLValue |
24412441 TVO_CanBindToNoEscape);
2442- // Attempt to lookup a member with a give name in the root type and
2443- // assign result to the leaf type of the keypath.
2444- bool isSubscriptRef = locator->isSubscriptMemberRef ();
2445- DeclNameRef memberName = isSubscriptRef
2446- ? DeclNameRef::createSubscript ()
2447- // FIXME: Should propagate name-as-written through.
2448- : DeclNameRef (choice.getName ());
2449-
2450- // Check the current depth of applied dynamic member lookups, if we've
2451- // exceeded the limit then record a fix and set a hole for the member.
2452- unsigned lookupDepth = [&]() {
2453- auto path = keyPathLoc->getPath ();
2454- auto iter = path.begin ();
2455- (void )keyPathLoc->findFirst <LocatorPathElt::KeyPathDynamicMember>(iter);
2456- return path.end () - iter;
2457- }();
2458- if (lookupDepth > ctx.TypeCheckerOpts .DynamicMemberLookupDepthLimit ) {
2459- (void )recordFix (TooManyDynamicMemberLookups::create (
2460- *this , DeclNameRef (choice.getName ()), locator));
2461- recordTypeVariablesAsHoles (memberTy);
2462- } else {
2463- addValueMemberConstraint (
2464- LValueType::get (rootTy), memberName, memberTy, useDC,
2465- isSubscriptRef ? FunctionRefInfo::doubleBaseNameApply ()
2466- : FunctionRefInfo::unappliedBaseName (),
2467- /* outerAlternatives=*/ {}, keyPathLoc);
2468- }
24692442
24702443 // In case of subscript things are more complicated comparing to "dot"
24712444 // syntax, because we have to get "applicable function" constraint
24722445 // associated with index expression and re-bind it to match "member type"
24732446 // looked up by dynamically.
2447+ bool isSubscriptRef = locator->isSubscriptMemberRef ();
24742448 if (isSubscriptRef) {
24752449 // Make sure that regular subscript declarations (if any) are
24762450 // preferred over key path dynamic member lookup.
@@ -2547,6 +2521,35 @@ void ConstraintSystem::bindOverloadType(const SelectedOverload &overload,
25472521 // fact that this a property access in the source.
25482522 addDynamicMemberSubscriptConstraints (/* argTy*/ paramTy, boundType);
25492523 }
2524+
2525+ // Attempt to lookup a member with a give name in the root type and
2526+ // assign result to the leaf type of the keypath. Note we need to do this
2527+ // after handling the applicable function constraint in the subscript case
2528+ // to ensure it's available for recursive cases.
2529+ DeclNameRef memberName = isSubscriptRef
2530+ ? DeclNameRef::createSubscript ()
2531+ // FIXME: Should propagate name-as-written through.
2532+ : DeclNameRef (choice.getName ());
2533+
2534+ // Check the current depth of applied dynamic member lookups, if we've
2535+ // exceeded the limit then record a fix and set a hole for the member.
2536+ unsigned lookupDepth = [&]() {
2537+ auto path = keyPathLoc->getPath ();
2538+ auto iter = path.begin ();
2539+ (void )keyPathLoc->findFirst <LocatorPathElt::KeyPathDynamicMember>(iter);
2540+ return path.end () - iter;
2541+ }();
2542+ if (lookupDepth > ctx.TypeCheckerOpts .DynamicMemberLookupDepthLimit ) {
2543+ (void )recordFix (TooManyDynamicMemberLookups::create (
2544+ *this , DeclNameRef (choice.getName ()), locator));
2545+ recordTypeVariablesAsHoles (memberTy);
2546+ } else {
2547+ addValueMemberConstraint (
2548+ LValueType::get (rootTy), memberName, memberTy, useDC,
2549+ isSubscriptRef ? FunctionRefInfo::doubleBaseNameApply ()
2550+ : FunctionRefInfo::unappliedBaseName (),
2551+ /* outerAlternatives=*/ {}, keyPathLoc);
2552+ }
25502553 return ;
25512554 }
25522555 }
0 commit comments