@@ -2421,11 +2421,30 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
24212421 return {swiftResultTy, importedType.isImplicitlyUnwrapped ()};
24222422}
24232423
2424+ static bool isParameterContextGlobalActorIsolated (DeclContext *dc,
2425+ const clang::Decl *parent) {
2426+ if (getActorIsolationOfContext (dc).isGlobalActor ())
2427+ return true ;
2428+
2429+ if (!parent->hasAttrs ())
2430+ return false ;
2431+
2432+ for (const auto *attr : parent->getAttrs ()) {
2433+ if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr)) {
2434+ if (isMainActorAttr (swiftAttr))
2435+ return true ;
2436+ }
2437+ }
2438+
2439+ return false ;
2440+ }
2441+
24242442std::optional<ClangImporter::Implementation::ImportParameterTypeResult>
24252443ClangImporter::Implementation::importParameterType (
2426- const clang::ParmVarDecl *param, OptionalTypeKind optionalityOfParam,
2427- bool allowNSUIntegerAsInt, bool isNSDictionarySubscriptGetter,
2428- bool paramIsError, bool paramIsCompletionHandler,
2444+ DeclContext *dc, const clang::Decl *parent, const clang::ParmVarDecl *param,
2445+ OptionalTypeKind optionalityOfParam, bool allowNSUIntegerAsInt,
2446+ bool isNSDictionarySubscriptGetter, bool paramIsError,
2447+ bool paramIsCompletionHandler,
24292448 std::optional<unsigned > completionHandlerErrorParamIndex,
24302449 ArrayRef<GenericTypeParamDecl *> genericParams,
24312450 llvm::function_ref<void (Diagnostic &&)> addImportDiagnosticFn) {
@@ -2445,7 +2464,8 @@ ClangImporter::Implementation::importParameterType(
24452464
24462465 if (SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
24472466 paramIsCompletionHandler) {
2448- attrs |= ImportTypeAttr::DefaultsToSendable;
2467+ if (!isParameterContextGlobalActorIsolated (dc, parent))
2468+ attrs |= ImportTypeAttr::DefaultsToSendable;
24492469 }
24502470
24512471 if (auto optionSetEnum = importer::findOptionSetEnum (paramTy, *this )) {
@@ -2722,13 +2742,13 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
27222742
27232743 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
27242744
2725- auto swiftParamTyOpt =
2726- importParameterType ( param, optionalityOfParam, allowNSUIntegerAsInt,
2727- /* isNSDictionarySubscriptGetter=*/ false ,
2728- /* paramIsError=*/ false ,
2729- /* paramIsCompletionHandler=*/ false ,
2730- /* completionHandlerErrorParamIndex=*/ std::nullopt ,
2731- genericParams, paramAddDiag);
2745+ auto swiftParamTyOpt = importParameterType (
2746+ dc, clangDecl, param, optionalityOfParam, allowNSUIntegerAsInt,
2747+ /* isNSDictionarySubscriptGetter=*/ false ,
2748+ /* paramIsError=*/ false ,
2749+ /* paramIsCompletionHandler=*/ false ,
2750+ /* completionHandlerErrorParamIndex=*/ std::nullopt , genericParams ,
2751+ paramAddDiag);
27322752 if (!swiftParamTyOpt) {
27332753 addImportDiagnostic (param,
27342754 Diagnostic (diag::parameter_type_not_imported, param),
@@ -3285,7 +3305,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
32853305 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
32863306
32873307 auto swiftParamTyOpt = importParameterType (
3288- param, optionalityOfParam, allowNSUIntegerAsIntInParam,
3308+ origDC, clangDecl, param, optionalityOfParam,
3309+ allowNSUIntegerAsIntInParam,
32893310 kind == SpecialMethodKind::NSDictionarySubscriptGetter, paramIsError,
32903311 paramIsCompletionHandler, completionHandlerErrorParamIndex,
32913312 ArrayRef<GenericTypeParamDecl *>(), paramAddDiag);
0 commit comments