@@ -2846,8 +2846,10 @@ namespace {
28462846 // or the original C type.
28472847 clang::QualType ClangType = Decl->getUnderlyingType ();
28482848 SwiftType = Impl.importTypeIgnoreIUO (
2849- ClangType, ImportTypeKind::Typedef, isInSystemModule (DC),
2850- getTypedefBridgeability (Decl), OTK_Optional);
2849+ ClangType, ImportTypeKind::Typedef,
2850+ ImportDiagnosticAdder (Impl, Decl, Decl->getLocation ()),
2851+ isInSystemModule (DC), getTypedefBridgeability (Decl),
2852+ getImportTypeAttrs (Decl), OTK_Optional);
28512853 }
28522854
28532855 if (!SwiftType)
@@ -2861,14 +2863,6 @@ namespace {
28612863 Loc,
28622864 /* genericparams*/ nullptr , DC);
28632865
2864- // If the typedef is marked with @Sendable and not @_nonSendable, make
2865- // any function type in it Sendable.
2866- auto sendability = Result->getAttrs ().getEffectiveSendableAttr ();
2867- if (isa_and_nonnull<SendableAttr>(sendability))
2868- SwiftType = applyToFunctionType (SwiftType, [](ASTExtInfo info) {
2869- return info.withConcurrent ();
2870- });
2871-
28722866 Result->setUnderlyingType (SwiftType);
28732867
28742868 // Make Objective-C's 'id' unavailable.
@@ -2950,6 +2944,7 @@ namespace {
29502944 auto name = importedName.getDeclName ().getBaseIdentifier ();
29512945
29522946 // Create the enum declaration and record it.
2947+ ImportDiagnosticAdder addDiag (Impl, decl, decl->getLocation ());
29532948 StructDecl *errorWrapper = nullptr ;
29542949 NominalTypeDecl *result;
29552950 auto enumInfo = Impl.getEnumInfo (decl);
@@ -2964,8 +2959,8 @@ namespace {
29642959 case EnumKind::Unknown: {
29652960 // Compute the underlying type of the enumeration.
29662961 auto underlyingType = Impl.importTypeIgnoreIUO (
2967- decl->getIntegerType (), ImportTypeKind::Enum, isInSystemModule (dc) ,
2968- Bridgeability::None);
2962+ decl->getIntegerType (), ImportTypeKind::Enum, addDiag ,
2963+ isInSystemModule (dc), Bridgeability::None, ImportTypeAttrs () );
29692964 if (!underlyingType)
29702965 return nullptr ;
29712966
@@ -2997,8 +2992,8 @@ namespace {
29972992
29982993 // Compute the underlying type.
29992994 auto underlyingType = Impl.importTypeIgnoreIUO (
3000- decl->getIntegerType (), ImportTypeKind::Enum, isInSystemModule (dc) ,
3001- Bridgeability::None);
2995+ decl->getIntegerType (), ImportTypeKind::Enum, addDiag ,
2996+ isInSystemModule (dc), Bridgeability::None, ImportTypeAttrs () );
30022997 if (!underlyingType)
30032998 return nullptr ;
30042999
@@ -3929,7 +3924,8 @@ namespace {
39293924 auto &clangContext = Impl.getClangASTContext ();
39303925 auto type = Impl.importTypeIgnoreIUO (
39313926 clangContext.getTagDeclType (clangEnum), ImportTypeKind::Value,
3932- isInSystemModule (dc), Bridgeability::None);
3927+ ImportDiagnosticAdder (Impl, clangEnum, clangEnum->getLocation ()),
3928+ isInSystemModule (dc), Bridgeability::None, ImportTypeAttrs ());
39333929 if (!type)
39343930 return nullptr ;
39353931
@@ -3995,7 +3991,9 @@ namespace {
39953991
39963992 auto importedType =
39973993 Impl.importType (decl->getType (), ImportTypeKind::Variable,
3998- isInSystemModule (dc), Bridgeability::None);
3994+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3995+ isInSystemModule (dc), Bridgeability::None,
3996+ getImportTypeAttrs (decl));
39993997 if (!importedType)
40003998 return nullptr ;
40013999
@@ -4522,7 +4520,9 @@ namespace {
45224520
45234521 auto importedType =
45244522 Impl.importType (decl->getType (), ImportTypeKind::RecordField,
4525- isInSystemModule (dc), Bridgeability::None);
4523+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
4524+ isInSystemModule (dc), Bridgeability::None,
4525+ getImportTypeAttrs (decl));
45264526 if (!importedType) {
45274527 Impl.addImportDiagnostic (
45284528 decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -4648,7 +4648,9 @@ namespace {
46484648 Impl.importType (declType,
46494649 (isAudited ? ImportTypeKind::AuditedVariable
46504650 : ImportTypeKind::Variable),
4651- isInSystemModule (dc), Bridgeability::None);
4651+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
4652+ isInSystemModule (dc), Bridgeability::None,
4653+ getImportTypeAttrs (decl));
46524654
46534655 if (!importedType)
46544656 return nullptr ;
@@ -5849,8 +5851,9 @@ namespace {
58495851 clangSuperclassType =
58505852 clangCtx.getObjCObjectPointerType (clangSuperclassType);
58515853 superclassType = Impl.importTypeIgnoreIUO (
5852- clangSuperclassType, ImportTypeKind::Abstract, isInSystemModule (dc),
5853- Bridgeability::None);
5854+ clangSuperclassType, ImportTypeKind::Abstract,
5855+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
5856+ isInSystemModule (dc), Bridgeability::None, ImportTypeAttrs ());
58545857 if (superclassType) {
58555858 assert (superclassType->is <ClassType>() ||
58565859 superclassType->is <BoundGenericClassType>());
@@ -6444,9 +6447,10 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
64446447 decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
64456448
64466449 // Import the type of the underlying storage
6450+ ImportDiagnosticAdder addImportDiag (Impl, decl, decl->getLocation ());
64476451 auto storedUnderlyingType = Impl.importTypeIgnoreIUO (
6448- decl->getUnderlyingType (), ImportTypeKind::Value, isInSystemModule (dc) ,
6449- Bridgeability::None, OTK_None);
6452+ decl->getUnderlyingType (), ImportTypeKind::Value, addImportDiag ,
6453+ isInSystemModule (dc), Bridgeability::None, ImportTypeAttrs () , OTK_None);
64506454
64516455 if (!storedUnderlyingType)
64526456 return nullptr ;
@@ -6466,8 +6470,8 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
64666470
64676471 // Find a bridged type, which may be different
64686472 auto computedPropertyUnderlyingType = Impl.importTypeIgnoreIUO (
6469- decl->getUnderlyingType (), ImportTypeKind::Property, isInSystemModule (dc) ,
6470- Bridgeability::Full, OTK_None);
6473+ decl->getUnderlyingType (), ImportTypeKind::Property, addImportDiag ,
6474+ isInSystemModule (dc), Bridgeability::Full, ImportTypeAttrs () , OTK_None);
64716475 if (auto objTy = computedPropertyUnderlyingType->getOptionalObjectType ())
64726476 computedPropertyUnderlyingType = objTy;
64736477
@@ -6726,8 +6730,9 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
67266730
67276731 // Compute the underlying type.
67286732 auto underlyingType = Impl.importTypeIgnoreIUO (
6729- decl->getIntegerType (), ImportTypeKind::Enum, isInSystemModule (dc),
6730- Bridgeability::None);
6733+ decl->getIntegerType (), ImportTypeKind::Enum,
6734+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
6735+ isInSystemModule (dc), Bridgeability::None, ImportTypeAttrs ());
67316736 if (!underlyingType)
67326737 return nullptr ;
67336738
@@ -6946,8 +6951,10 @@ SwiftDeclConverter::getImplicitProperty(ImportedName importedName,
69466951 bool isFromSystemModule = isInSystemModule (dc);
69476952 auto importedType = Impl.importType (
69486953 propertyType, ImportTypeKind::Property,
6954+ ImportDiagnosticAdder (Impl, getter, getter->getLocation ()),
69496955 Impl.shouldAllowNSUIntegerAsInt (isFromSystemModule, getter),
6950- Bridgeability::Full, OTK_ImplicitlyUnwrappedOptional);
6956+ Bridgeability::Full, getImportTypeAttrs (accessor),
6957+ OTK_ImplicitlyUnwrappedOptional);
69516958 if (!importedType)
69526959 return nullptr ;
69536960
@@ -8130,9 +8137,12 @@ Optional<GenericParamList *> SwiftDeclConverter::importObjCGenericParams(
81308137 if (clangBound->getInterfaceDecl ()) {
81318138 auto unqualifiedClangBound =
81328139 clangBound->stripObjCKindOfTypeAndQuals (Impl.getClangASTContext ());
8140+ assert (!objcGenericParam->hasAttrs ()
8141+ && " ObjC generics can have attributes now--we should use 'em" );
81338142 Type superclassType = Impl.importTypeIgnoreIUO (
81348143 clang::QualType (unqualifiedClangBound, 0 ), ImportTypeKind::Abstract,
8135- false , Bridgeability::None);
8144+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
8145+ false , Bridgeability::None, ImportTypeAttrs ());
81368146 if (!superclassType) {
81378147 return None;
81388148 }
@@ -8852,6 +8862,15 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
88528862 if (isa<TypeAliasDecl>(MappedDecl))
88538863 return ;
88548864
8865+ // `@Sendable` on non-types is treated as an `ImportTypeAttr` and shouldn't
8866+ // be treated as an attribute on the declaration. (Particularly, @Sendable on
8867+ // a function or method should be treated as making the return value Sendable,
8868+ // *not* as making the function/method itself Sendable, because
8869+ // `@Sendable func` is primarily meant for local functions.)
8870+ if (!isa<TypeDecl>(MappedDecl))
8871+ while (auto attr = MappedDecl->getAttrs ().getEffectiveSendableAttr ())
8872+ MappedDecl->getAttrs ().removeAttribute (attr);
8873+
88558874 // Some types have an implicit '@Sendable' attribute.
88568875 if (ClangDecl->hasAttr <clang::SwiftNewTypeAttr>() ||
88578876 ClangDecl->hasAttr <clang::EnumExtensibilityAttr>() ||
0 commit comments