@@ -2426,6 +2426,27 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
2426
2426
return type;
2427
2427
}
2428
2428
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
+
2429
2450
bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
2430
2451
// If this is a compiler synthesized implicit conversion, let's skip
2431
2452
// the check because the base of `UDE` is not the base of the injected
@@ -2440,20 +2461,7 @@ bool ConstraintSystem::isPartialApplication(ConstraintLocator *locator) {
2440
2461
2441
2462
auto baseTy =
2442
2463
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 ;
2457
2465
}
2458
2466
2459
2467
DeclReferenceType
@@ -3088,18 +3096,7 @@ isInvalidPartialApplication(ConstraintSystem &cs,
3088
3096
if (!isInvalidIfPartiallyApplied ())
3089
3097
return {false ,0 };
3090
3098
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)};
3103
3100
}
3104
3101
3105
3102
FunctionType::ExtInfo ConstraintSystem::closureEffects (ClosureExpr *expr) {
0 commit comments