@@ -2846,8 +2846,10 @@ namespace {
2846
2846
// or the original C type.
2847
2847
clang::QualType ClangType = Decl->getUnderlyingType ();
2848
2848
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);
2851
2853
}
2852
2854
2853
2855
if (!SwiftType)
@@ -2861,14 +2863,6 @@ namespace {
2861
2863
Loc,
2862
2864
/* genericparams*/ nullptr , DC);
2863
2865
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
-
2872
2866
Result->setUnderlyingType (SwiftType);
2873
2867
2874
2868
// Make Objective-C's 'id' unavailable.
@@ -2950,6 +2944,7 @@ namespace {
2950
2944
auto name = importedName.getDeclName ().getBaseIdentifier ();
2951
2945
2952
2946
// Create the enum declaration and record it.
2947
+ ImportDiagnosticAdder addDiag (Impl, decl, decl->getLocation ());
2953
2948
StructDecl *errorWrapper = nullptr ;
2954
2949
NominalTypeDecl *result;
2955
2950
auto enumInfo = Impl.getEnumInfo (decl);
@@ -2964,8 +2959,8 @@ namespace {
2964
2959
case EnumKind::Unknown: {
2965
2960
// Compute the underlying type of the enumeration.
2966
2961
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 () );
2969
2964
if (!underlyingType)
2970
2965
return nullptr ;
2971
2966
@@ -2997,8 +2992,8 @@ namespace {
2997
2992
2998
2993
// Compute the underlying type.
2999
2994
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 () );
3002
2997
if (!underlyingType)
3003
2998
return nullptr ;
3004
2999
@@ -3929,7 +3924,8 @@ namespace {
3929
3924
auto &clangContext = Impl.getClangASTContext ();
3930
3925
auto type = Impl.importTypeIgnoreIUO (
3931
3926
clangContext.getTagDeclType (clangEnum), ImportTypeKind::Value,
3932
- isInSystemModule (dc), Bridgeability::None);
3927
+ ImportDiagnosticAdder (Impl, clangEnum, clangEnum->getLocation ()),
3928
+ isInSystemModule (dc), Bridgeability::None, ImportTypeAttrs ());
3933
3929
if (!type)
3934
3930
return nullptr ;
3935
3931
@@ -3995,7 +3991,9 @@ namespace {
3995
3991
3996
3992
auto importedType =
3997
3993
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));
3999
3997
if (!importedType)
4000
3998
return nullptr ;
4001
3999
@@ -4522,7 +4520,9 @@ namespace {
4522
4520
4523
4521
auto importedType =
4524
4522
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));
4526
4526
if (!importedType) {
4527
4527
Impl.addImportDiagnostic (
4528
4528
decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -4648,7 +4648,9 @@ namespace {
4648
4648
Impl.importType (declType,
4649
4649
(isAudited ? ImportTypeKind::AuditedVariable
4650
4650
: ImportTypeKind::Variable),
4651
- isInSystemModule (dc), Bridgeability::None);
4651
+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
4652
+ isInSystemModule (dc), Bridgeability::None,
4653
+ getImportTypeAttrs (decl));
4652
4654
4653
4655
if (!importedType)
4654
4656
return nullptr ;
@@ -5849,8 +5851,9 @@ namespace {
5849
5851
clangSuperclassType =
5850
5852
clangCtx.getObjCObjectPointerType (clangSuperclassType);
5851
5853
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 ());
5854
5857
if (superclassType) {
5855
5858
assert (superclassType->is <ClassType>() ||
5856
5859
superclassType->is <BoundGenericClassType>());
@@ -6444,9 +6447,10 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
6444
6447
decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
6445
6448
6446
6449
// Import the type of the underlying storage
6450
+ ImportDiagnosticAdder addImportDiag (Impl, decl, decl->getLocation ());
6447
6451
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);
6450
6454
6451
6455
if (!storedUnderlyingType)
6452
6456
return nullptr ;
@@ -6466,8 +6470,8 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
6466
6470
6467
6471
// Find a bridged type, which may be different
6468
6472
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);
6471
6475
if (auto objTy = computedPropertyUnderlyingType->getOptionalObjectType ())
6472
6476
computedPropertyUnderlyingType = objTy;
6473
6477
@@ -6726,8 +6730,9 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
6726
6730
6727
6731
// Compute the underlying type.
6728
6732
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 ());
6731
6736
if (!underlyingType)
6732
6737
return nullptr ;
6733
6738
@@ -6946,8 +6951,10 @@ SwiftDeclConverter::getImplicitProperty(ImportedName importedName,
6946
6951
bool isFromSystemModule = isInSystemModule (dc);
6947
6952
auto importedType = Impl.importType (
6948
6953
propertyType, ImportTypeKind::Property,
6954
+ ImportDiagnosticAdder (Impl, getter, getter->getLocation ()),
6949
6955
Impl.shouldAllowNSUIntegerAsInt (isFromSystemModule, getter),
6950
- Bridgeability::Full, OTK_ImplicitlyUnwrappedOptional);
6956
+ Bridgeability::Full, getImportTypeAttrs (accessor),
6957
+ OTK_ImplicitlyUnwrappedOptional);
6951
6958
if (!importedType)
6952
6959
return nullptr ;
6953
6960
@@ -8130,9 +8137,12 @@ Optional<GenericParamList *> SwiftDeclConverter::importObjCGenericParams(
8130
8137
if (clangBound->getInterfaceDecl ()) {
8131
8138
auto unqualifiedClangBound =
8132
8139
clangBound->stripObjCKindOfTypeAndQuals (Impl.getClangASTContext ());
8140
+ assert (!objcGenericParam->hasAttrs ()
8141
+ && " ObjC generics can have attributes now--we should use 'em" );
8133
8142
Type superclassType = Impl.importTypeIgnoreIUO (
8134
8143
clang::QualType (unqualifiedClangBound, 0 ), ImportTypeKind::Abstract,
8135
- false , Bridgeability::None);
8144
+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
8145
+ false , Bridgeability::None, ImportTypeAttrs ());
8136
8146
if (!superclassType) {
8137
8147
return None;
8138
8148
}
@@ -8852,6 +8862,15 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8852
8862
if (isa<TypeAliasDecl>(MappedDecl))
8853
8863
return ;
8854
8864
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
+
8855
8874
// Some types have an implicit '@Sendable' attribute.
8856
8875
if (ClangDecl->hasAttr <clang::SwiftNewTypeAttr>() ||
8857
8876
ClangDecl->hasAttr <clang::EnumExtensibilityAttr>() ||
0 commit comments