@@ -2446,38 +2446,12 @@ void ConstraintSystem::bindOverloadType(const SelectedOverload &overload,
24462446 // don't which at the moment, so let's allow its type to be l-value.
24472447 auto memberTy = createTypeVariable (keyPathLoc, TVO_CanBindToLValue |
24482448 TVO_CanBindToNoEscape);
2449- // Attempt to lookup a member with a give name in the root type and
2450- // assign result to the leaf type of the keypath.
2451- bool isSubscriptRef = locator->isSubscriptMemberRef ();
2452- DeclNameRef memberName = isSubscriptRef
2453- ? DeclNameRef::createSubscript ()
2454- // FIXME: Should propagate name-as-written through.
2455- : DeclNameRef (choice.getName ());
2456-
2457- // Check the current depth of applied dynamic member lookups, if we've
2458- // exceeded the limit then record a fix and set a hole for the member.
2459- unsigned lookupDepth = [&]() {
2460- auto path = keyPathLoc->getPath ();
2461- auto iter = path.begin ();
2462- (void )keyPathLoc->findFirst <LocatorPathElt::KeyPathDynamicMember>(iter);
2463- return path.end () - iter;
2464- }();
2465- if (lookupDepth > ctx.TypeCheckerOpts .DynamicMemberLookupDepthLimit ) {
2466- (void )recordFix (TooManyDynamicMemberLookups::create (
2467- *this , DeclNameRef (choice.getName ()), locator));
2468- recordTypeVariablesAsHoles (memberTy);
2469- } else {
2470- addValueMemberConstraint (
2471- LValueType::get (rootTy), memberName, memberTy, useDC,
2472- isSubscriptRef ? FunctionRefInfo::doubleBaseNameApply ()
2473- : FunctionRefInfo::unappliedBaseName (),
2474- /* outerAlternatives=*/ {}, keyPathLoc);
2475- }
24762449
24772450 // In case of subscript things are more complicated comparing to "dot"
24782451 // syntax, because we have to get "applicable function" constraint
24792452 // associated with index expression and re-bind it to match "member type"
24802453 // looked up by dynamically.
2454+ bool isSubscriptRef = locator->isSubscriptMemberRef ();
24812455 if (isSubscriptRef) {
24822456 // Make sure that regular subscript declarations (if any) are
24832457 // preferred over key path dynamic member lookup.
@@ -2554,6 +2528,35 @@ void ConstraintSystem::bindOverloadType(const SelectedOverload &overload,
25542528 // fact that this a property access in the source.
25552529 addDynamicMemberSubscriptConstraints (/* argTy*/ paramTy, boundType);
25562530 }
2531+
2532+ // Attempt to lookup a member with a give name in the root type and
2533+ // assign result to the leaf type of the keypath. Note we need to do this
2534+ // after handling the applicable function constraint in the subscript case
2535+ // to ensure it's available for recursive cases.
2536+ DeclNameRef memberName = isSubscriptRef
2537+ ? DeclNameRef::createSubscript ()
2538+ // FIXME: Should propagate name-as-written through.
2539+ : DeclNameRef (choice.getName ());
2540+
2541+ // Check the current depth of applied dynamic member lookups, if we've
2542+ // exceeded the limit then record a fix and set a hole for the member.
2543+ unsigned lookupDepth = [&]() {
2544+ auto path = keyPathLoc->getPath ();
2545+ auto iter = path.begin ();
2546+ (void )keyPathLoc->findFirst <LocatorPathElt::KeyPathDynamicMember>(iter);
2547+ return path.end () - iter;
2548+ }();
2549+ if (lookupDepth > ctx.TypeCheckerOpts .DynamicMemberLookupDepthLimit ) {
2550+ (void )recordFix (TooManyDynamicMemberLookups::create (
2551+ *this , DeclNameRef (choice.getName ()), locator));
2552+ recordTypeVariablesAsHoles (memberTy);
2553+ } else {
2554+ addValueMemberConstraint (
2555+ LValueType::get (rootTy), memberName, memberTy, useDC,
2556+ isSubscriptRef ? FunctionRefInfo::doubleBaseNameApply ()
2557+ : FunctionRefInfo::unappliedBaseName (),
2558+ /* outerAlternatives=*/ {}, keyPathLoc);
2559+ }
25572560 return ;
25582561 }
25592562 }
0 commit comments