@@ -2426,6 +2426,27 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
24262426 return type;
24272427}
24282428
2429+ static unsigned getApplicationLevel (ConstraintSystem &CS, Type baseTy,
2430+ UnresolvedDotExpr *UDE) {
2431+ unsigned level = 0 ;
2432+
2433+ // If base is a metatype it would be ignored (unless this is an initializer
2434+ // call), but if it is some other type it means that we have a single
2435+ // application level already.
2436+ if (!baseTy->is <MetatypeType>())
2437+ ++level;
2438+
2439+ if (auto *call = dyn_cast_or_null<CallExpr>(CS.getParentExpr (UDE))) {
2440+ // Reference is applied only if it appears in a function position
2441+ // in the parent call expression - i.e. `x(...)` vs. `y(x)`,
2442+ // the latter doesn't have `x` applied.
2443+ if (UDE == call->getFn ()->getSemanticsProvidingExpr ())
2444+ level += 1 ;
2445+ }
2446+
2447+ return level;
2448+ }
2449+
24292450bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
24302451 // If this is a compiler synthesized implicit conversion, let's skip
24312452 // the check because the base of `UDE` is not the base of the injected
@@ -2440,20 +2461,7 @@ bool ConstraintSystem::isPartialApplication(ConstraintLocator *locator) {
24402461
24412462 auto baseTy =
24422463 simplifyType (getType (UDE->getBase ()))->getWithoutSpecifierType ();
2443-
2444- // If base is a metatype it would be ignored (unless this is an initializer
2445- // call), but if it is some other type it means that we have a single
2446- // application level already.
2447- unsigned level = 0 ;
2448- if (!baseTy->is <MetatypeType>())
2449- ++level;
2450-
2451- if (auto *call = dyn_cast_or_null<CallExpr>(getParentExpr (UDE))) {
2452- if (UDE == call->getFn ()->getSemanticsProvidingExpr ())
2453- level += 1 ;
2454- }
2455-
2456- return level < 2 ;
2464+ return getApplicationLevel (*this , baseTy, UDE) < 2 ;
24572465}
24582466
24592467DeclReferenceType
@@ -3088,18 +3096,7 @@ isInvalidPartialApplication(ConstraintSystem &cs,
30883096 if (!isInvalidIfPartiallyApplied ())
30893097 return {false ,0 };
30903098
3091- // If base is a metatype it would be ignored (unless this is an initializer
3092- // call), but if it is some other type it means that we have a single
3093- // application level already.
3094- unsigned level = 0 ;
3095- if (!baseTy->is <MetatypeType>())
3096- ++level;
3097-
3098- if (auto *call = dyn_cast_or_null<CallExpr>(cs.getParentExpr (UDE))) {
3099- level += 1 ;
3100- }
3101-
3102- return {true , level};
3099+ return {true , getApplicationLevel (cs, baseTy, UDE)};
31033100}
31043101
31053102FunctionType::ExtInfo ConstraintSystem::closureEffects (ClosureExpr *expr) {
0 commit comments