@@ -1665,8 +1665,6 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
16651665 FunctionRefKind functionRefKind,
16661666 ConstraintLocatorBuilder locator,
16671667 DeclContext *useDC) {
1668- auto &ctx = getASTContext ();
1669-
16701668 if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
16711669 // Unqualified lookup can find operator names within nominal types.
16721670 auto func = cast<FuncDecl>(value);
@@ -1715,7 +1713,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
17151713
17161714 if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
17171715 // All global functions should be @Sendable
1718- if (!funcDecl->getDeclContext ()->isTypeContext () && !funcDecl->getDeclContext ()->isLocalContext () ) {
1716+ if (!funcDecl->getDeclContext ()->isTypeContext () &&
1717+ !funcDecl->getDeclContext ()->isLocalContext ()) {
17191718 funcType =
17201719 funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ());
17211720 }
@@ -1724,7 +1723,9 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
17241723 auto openedType = openFunctionType (funcType, locator, replacements,
17251724 funcDecl->getDeclContext ())
17261725 ->removeArgumentLabels (numLabelsToRemove);
1727- openedType = unwrapPropertyWrapperParameterTypes (*this , funcDecl, functionRefKind, openedType->castTo <FunctionType>(), locator);
1726+ openedType = unwrapPropertyWrapperParameterTypes (
1727+ *this , funcDecl, functionRefKind, openedType->castTo <FunctionType>(),
1728+ locator);
17281729
17291730 auto origOpenedType = openedType;
17301731 if (!isRequirementOrWitness (locator)) {
@@ -2426,6 +2427,27 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
24262427 return type;
24272428}
24282429
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+
24292451bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
24302452 // If this is a compiler synthesized implicit conversion, let's skip
24312453 // the check because the base of `UDE` is not the base of the injected
@@ -2440,20 +2462,7 @@ bool ConstraintSystem::isPartialApplication(ConstraintLocator *locator) {
24402462
24412463 auto baseTy =
24422464 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 ;
24572466}
24582467
24592468DeclReferenceType
@@ -2671,7 +2680,10 @@ ConstraintSystem::getTypeOfMemberReference(
26712680 if (isPartialApplication (locator) &&
26722681 isSendableType (DC->getParentModule (), baseOpenedTy)) {
26732682 // 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>();
26752687 }
26762688 // Unapplied values should always be Sendable
26772689 info = info.withConcurrent ();
@@ -3088,18 +3100,7 @@ isInvalidPartialApplication(ConstraintSystem &cs,
30883100 if (!isInvalidIfPartiallyApplied ())
30893101 return {false ,0 };
30903102
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)};
31033104}
31043105
31053106FunctionType::ExtInfo ConstraintSystem::closureEffects (ClosureExpr *expr) {
0 commit comments