@@ -1665,8 +1665,6 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1665
1665
FunctionRefKind functionRefKind,
1666
1666
ConstraintLocatorBuilder locator,
1667
1667
DeclContext *useDC) {
1668
- auto &ctx = getASTContext ();
1669
-
1670
1668
if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
1671
1669
// Unqualified lookup can find operator names within nominal types.
1672
1670
auto func = cast<FuncDecl>(value);
@@ -1715,7 +1713,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1715
1713
1716
1714
if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
1717
1715
// All global functions should be @Sendable
1718
- if (!funcDecl->getDeclContext ()->isTypeContext () && !funcDecl->getDeclContext ()->isLocalContext () ) {
1716
+ if (!funcDecl->getDeclContext ()->isTypeContext () &&
1717
+ !funcDecl->getDeclContext ()->isLocalContext ()) {
1719
1718
funcType =
1720
1719
funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ());
1721
1720
}
@@ -1724,7 +1723,9 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1724
1723
auto openedType = openFunctionType (funcType, locator, replacements,
1725
1724
funcDecl->getDeclContext ())
1726
1725
->removeArgumentLabels (numLabelsToRemove);
1727
- openedType = unwrapPropertyWrapperParameterTypes (*this , funcDecl, functionRefKind, openedType->castTo <FunctionType>(), locator);
1726
+ openedType = unwrapPropertyWrapperParameterTypes (
1727
+ *this , funcDecl, functionRefKind, openedType->castTo <FunctionType>(),
1728
+ locator);
1728
1729
1729
1730
auto origOpenedType = openedType;
1730
1731
if (!isRequirementOrWitness (locator)) {
@@ -2426,6 +2427,27 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
2426
2427
return type;
2427
2428
}
2428
2429
2430
+ static unsigned getApplicationLevel (ConstraintSystem &CS, Type baseTy,
2431
+ UnresolvedDotExpr *UDE) {
2432
+ unsigned level = 0 ;
2433
+
2434
+ // If base is a metatype it would be ignored (unless this is an initializer
2435
+ // call), but if it is some other type it means that we have a single
2436
+ // application level already.
2437
+ if (!baseTy->is <MetatypeType>())
2438
+ ++level;
2439
+
2440
+ if (auto *call = dyn_cast_or_null<CallExpr>(CS.getParentExpr (UDE))) {
2441
+ // Reference is applied only if it appears in a function position
2442
+ // in the parent call expression - i.e. `x(...)` vs. `y(x)`,
2443
+ // the latter doesn't have `x` applied.
2444
+ if (UDE == call->getFn ()->getSemanticsProvidingExpr ())
2445
+ level += 1 ;
2446
+ }
2447
+
2448
+ return level;
2449
+ }
2450
+
2429
2451
bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
2430
2452
// If this is a compiler synthesized implicit conversion, let's skip
2431
2453
// the check because the base of `UDE` is not the base of the injected
@@ -2440,20 +2462,7 @@ bool ConstraintSystem::isPartialApplication(ConstraintLocator *locator) {
2440
2462
2441
2463
auto baseTy =
2442
2464
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 ;
2465
+ return getApplicationLevel (*this , baseTy, UDE) < 2 ;
2457
2466
}
2458
2467
2459
2468
DeclReferenceType
@@ -2671,7 +2680,10 @@ ConstraintSystem::getTypeOfMemberReference(
2671
2680
if (isPartialApplication (locator) &&
2672
2681
isSendableType (DC->getParentModule (), baseOpenedTy)) {
2673
2682
// Add @Sendable to functions without conditional conformances
2674
- functionType = functionType->withExtInfo (functionType->getExtInfo ().withConcurrent ())->getAs <FunctionType>();
2683
+ functionType =
2684
+ functionType
2685
+ ->withExtInfo (functionType->getExtInfo ().withConcurrent ())
2686
+ ->getAs <FunctionType>();
2675
2687
}
2676
2688
// Unapplied values should always be Sendable
2677
2689
info = info.withConcurrent ();
@@ -3088,18 +3100,7 @@ isInvalidPartialApplication(ConstraintSystem &cs,
3088
3100
if (!isInvalidIfPartiallyApplied ())
3089
3101
return {false ,0 };
3090
3102
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};
3103
+ return {true , getApplicationLevel (cs, baseTy, UDE)};
3103
3104
}
3104
3105
3105
3106
FunctionType::ExtInfo ConstraintSystem::closureEffects (ClosureExpr *expr) {
0 commit comments