Skip to content

Commit b7a8349

Browse files
committed
Expand DisallowedOriginKind with an explicit entry for internal bridging headers
1 parent d04e6dd commit b7a8349

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,6 +3834,7 @@ ERROR(decl_from_hidden_module,none,
38343834
"%2 was imported for SPI only|"
38353835
"%2 was not imported by this file|"
38363836
"C++ types from imported module %2 do not support library evolution|"
3837+
"it was imported via the internal bridging header|"
38373838
"%2 was not imported publicly}3",
38383839
(const Decl *, unsigned, Identifier, unsigned))
38393840
ERROR(typealias_desugars_to_type_from_hidden_module,none,
@@ -3850,6 +3851,7 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
38503851
"%4 was imported for SPI only|"
38513852
"%4 was not imported by this file|"
38523853
"C++ types from imported module %4 do not support library evolution|"
3854+
"it was imported via the internal bridging header|"
38533855
"%4 was not imported publicly}5",
38543856
(const TypeAliasDecl *, StringRef, StringRef, unsigned, Identifier, unsigned))
38553857
ERROR(conformance_from_implementation_only_module,none,
@@ -3864,6 +3866,7 @@ ERROR(conformance_from_implementation_only_module,none,
38643866
"%3 was imported for SPI only|"
38653867
"%3 was not imported by this file|"
38663868
"C++ types from imported module %3 do not support library evolution|"
3869+
"it was imported via the internal bridging header|"
38673870
"%3 was not imported publicly}4",
38683871
(Type, Identifier, unsigned, Identifier, unsigned))
38693872
NOTE(assoc_conformance_from_implementation_only_module,none,
@@ -7317,6 +7320,7 @@ ERROR(inlinable_decl_ref_from_hidden_module,
73177320
"%2 was imported for SPI only|"
73187321
"%2 was not imported by this file|"
73197322
"C++ APIs from imported module %2 do not support library evolution|"
7323+
"it was imported via the internal bridging header|"
73207324
"%2 was not imported publicly}3",
73217325
(const ValueDecl *, unsigned, Identifier, unsigned))
73227326

@@ -7328,6 +7332,7 @@ ERROR(inlinable_typealias_desugars_to_type_from_hidden_module,
73287332
"%4 was imported for SPI only|"
73297333
"%4 was not imported by this file|"
73307334
"C++ types from imported module %4 do not support library evolution|"
7335+
"it was imported via the internal bridging header|"
73317336
"%4 was not imported publicly}5",
73327337
(const TypeAliasDecl *, StringRef, StringRef, unsigned, Identifier, unsigned))
73337338

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
277277
D, DC, AccessLevel::Public,
278278
[&](AttributedImport<ImportedModule> attributedImport) {
279279
if (where.isExported() && reason != ExportabilityReason::General &&
280-
originKind != DisallowedOriginKind::NonPublicImport) {
280+
originKind != DisallowedOriginKind::NonPublicImport &&
281+
originKind != DisallowedOriginKind::InternalBridgingHeaderImport) {
281282
// These may be reported twice, for the Type and for the TypeRepr.
282283
ModuleDecl *importedVia = attributedImport.module.importedModule,
283284
*sourceModule = D->getModuleContext();
@@ -294,6 +295,7 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
294295
return false;
295296

296297
case DisallowedOriginKind::NonPublicImport:
298+
case DisallowedOriginKind::InternalBridgingHeaderImport:
297299
// With a few exceptions, access levels from imports are diagnosed during
298300
// access checking and should be skipped here.
299301
if (!shouldDiagnoseDeclAccess(D, where))

lib/Sema/TypeCheckAccess.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,8 +2167,11 @@ swift::getDisallowedOriginKind(const Decl *decl,
21672167
// See \c diagnoseValueDeclRefExportability.
21682168
auto importSource = decl->getImportAccessFrom(where.getDeclContext());
21692169
if (importSource.has_value() &&
2170-
importSource->accessLevel < AccessLevel::Public)
2171-
return DisallowedOriginKind::NonPublicImport;
2170+
importSource->accessLevel < AccessLevel::Public) {
2171+
return importSource->module.importedModule->isClangHeaderImportModule()
2172+
? DisallowedOriginKind::InternalBridgingHeaderImport
2173+
: DisallowedOriginKind::NonPublicImport;
2174+
}
21722175

21732176
return DisallowedOriginKind::None;
21742177
}

lib/Sema/TypeCheckAccess.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ enum class DisallowedOriginKind : uint8_t {
4747
SPIOnly,
4848
MissingImport,
4949
FragileCxxAPI,
50+
51+
/// An import that is internal via the internally-imported bridging header.
52+
InternalBridgingHeaderImport,
53+
5054
NonPublicImport,
5155
None
5256
};

test/ClangImporter/Inputs/c-bridging-header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ typedef struct {
88
double x, y;
99
} MyPoint;
1010

11+
typedef double MyDouble;
1112
#endif

test/ClangImporter/InternalBridgingHeader/access_checking.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ public func getX(point: MyPoint) -> Double { point.x } // expected-error{{functi
2020

2121
// Comes from the macros module.
2222
public func returnsFromMacrosModule() -> okay_t { 0 }
23+
24+
public protocol P {
25+
associatedtype A
26+
}
27+
28+
public struct MyType: P {
29+
public typealias A = MyDouble
30+
// expected-error@-1{{type alias cannot be declared public because its underlying type uses an internal type}}
31+
// expected-note@-2{{type alias 'MyDouble' is imported by this file as 'internal' from bridging header}}
32+
}
33+
34+
// expected-error@+1{{cannot use struct 'MyPoint' in an extension with public or '@usableFromInline' members; it was imported via the internal bridging header}}
35+
extension MyPoint: P {
36+
public typealias A = MyDouble
37+
// expected-error@-1{{type alias cannot be declared public because its underlying type uses an internal type}}
38+
// expected-note@-2{{type alias 'MyDouble' is imported by this file as 'internal' from bridging header}}
39+
}

0 commit comments

Comments
 (0)