@@ -1664,6 +1664,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1664
1664
FunctionRefKind functionRefKind,
1665
1665
ConstraintLocatorBuilder locator,
1666
1666
DeclContext *useDC) {
1667
+ auto &ctx = getASTContext ();
1668
+
1667
1669
if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
1668
1670
// Unqualified lookup can find operator names within nominal types.
1669
1671
auto func = cast<FuncDecl>(value);
@@ -1709,7 +1711,14 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1709
1711
auto funcType = funcDecl->getInterfaceType ()->castTo <AnyFunctionType>();
1710
1712
auto numLabelsToRemove = getNumRemovedArgumentLabels (
1711
1713
funcDecl, /* isCurriedInstanceReference=*/ false , functionRefKind);
1712
-
1714
+
1715
+ if (ctx.LangOpts .hasFeature (Feature::InferSendableMethods)) {
1716
+ // All global functions should be @Sendable
1717
+ if (funcDecl->getDeclContext ()->isLocalContext ()) {
1718
+ funcType = funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ())->getAs <AnyFunctionType>();
1719
+ }
1720
+ }
1721
+
1713
1722
auto openedType = openFunctionType (funcType, locator, replacements,
1714
1723
funcDecl->getDeclContext ())
1715
1724
->removeArgumentLabels (numLabelsToRemove);
@@ -2625,7 +2634,7 @@ ConstraintSystem::getTypeOfMemberReference(
2625
2634
functionType, locator);
2626
2635
auto &ctx = DC->getASTContext ();
2627
2636
auto *parentModule = useDC->getParentModule ();
2628
- bool baseSendable = isSendableType (parentModule, baseOpenedTy);
2637
+ bool baseTypeSendable = isSendableType (parentModule, baseOpenedTy);
2629
2638
bool inferredSendable =
2630
2639
ctx.LangOpts .hasFeature (Feature::InferSendableMethods);
2631
2640
@@ -2635,20 +2644,24 @@ ConstraintSystem::getTypeOfMemberReference(
2635
2644
auto baseConformance = TypeChecker::conformsToProtocol (
2636
2645
baseOpenedTy, sendableProtocol, parentModule);
2637
2646
2638
- if (baseSendable ) {
2647
+ if (baseTypeSendable ) {
2639
2648
// Add @Sendable to functions without conditional conformances
2640
- if (baseConformance.getConditionalRequirements ().empty ())
2649
+ if (baseConformance.getConditionalRequirements ().empty ()){
2641
2650
functionType = functionType->withExtInfo (functionType->getExtInfo ().withConcurrent ())->getAs <FunctionType>();
2642
-
2643
- // Handle Conditional Conformances
2644
- for (auto req : baseConformance.getConditionalRequirements ()) {
2645
- if (!TypeChecker::conformsToProtocol (req.getFirstType (),
2646
- sendableProtocol, parentModule)
2647
- .isInvalid ())
2651
+ } else {
2652
+ // Handle Conditional Conformances
2653
+ auto substitutionMap = SubstitutionMap::getProtocolSubstitutions (
2654
+ sendableProtocol, baseOpenedTy,
2655
+ baseConformance);
2656
+
2657
+ auto result = TypeChecker::checkGenericArguments (parentModule, baseConformance.getConditionalRequirements (), QuerySubstitutionMap{substitutionMap} );
2658
+
2659
+ if (result == CheckGenericArgumentsResult::Success) {
2648
2660
functionType =
2649
- functionType
2650
- ->withExtInfo (functionType->getExtInfo ().withConcurrent ())
2651
- ->getAs <FunctionType>();
2661
+ functionType
2662
+ ->withExtInfo (functionType->getExtInfo ().withConcurrent ())
2663
+ ->getAs <FunctionType>();
2664
+ }
2652
2665
}
2653
2666
}
2654
2667
}
@@ -2659,10 +2672,10 @@ ConstraintSystem::getTypeOfMemberReference(
2659
2672
FunctionType::get (fullFunctionType->getParams (), functionType, info);
2660
2673
2661
2674
// Add @Sendable to openedType if possible
2662
- if (inferredSendable && baseSendable) {
2675
+ if (inferredSendable) {
2663
2676
auto origFnType = openedType->castTo <FunctionType>();
2664
2677
openedType =
2665
- origFnType->withExtInfo (origFnType->getExtInfo ().withConcurrent ());
2678
+ origFnType->withExtInfo (origFnType->getExtInfo ().withConcurrent ());
2666
2679
}
2667
2680
}
2668
2681
0 commit comments