Improve some diagnostic with @_implementationOnly violations from internal bridging headers

This commit is contained in:
Doug Gregor
2025-09-19 16:48:22 -07:00
parent 30bdb6b37a
commit 7bc02d6a70
4 changed files with 38 additions and 7 deletions

View File

@@ -2702,8 +2702,8 @@ NOTE(module_imported_here,none,
NOTE(decl_import_via_here,none,
"%kind0 imported as "
"'%select{private|fileprivate|internal|package|%ERROR|%ERROR}1' "
"from %2 here",
(const Decl *, AccessLevel, const ModuleDecl*))
"from %select{%2 here|bridging header}3",
(const Decl *, AccessLevel, const ModuleDecl*, bool))
NOTE(decl_import_via_local,none,
"%kind0 is imported by this file as "
"'%select{private|fileprivate|internal|package|%ERROR|%ERROR}1' "

View File

@@ -133,7 +133,9 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
Context.Diags.diagnose(problematicImport->importLoc,
diag::decl_import_via_here, D,
problematicImport->accessLevel,
problematicImport->module.importedModule);
problematicImport->module.importedModule,
problematicImport->module.importedModule
->isClangHeaderImportModule());
}
return (downgradeToWarning == DowngradeToWarning::No);
@@ -213,7 +215,9 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
ctx.Diags.diagnose(limitImport->importLoc,
diag::decl_import_via_here, D,
limitImport->accessLevel,
limitImport->module.importedModule);
limitImport->module.importedModule,
limitImport->module.importedModule
->isClangHeaderImportModule());
}
return true;
@@ -368,7 +372,9 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
ctx.Diags.diagnose(import->importLoc,
diag::decl_import_via_here, D,
import->accessLevel,
import->module.importedModule);
import->module.importedModule,
import->module.importedModule
->isClangHeaderImportModule());
}
return true;
@@ -454,7 +460,9 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
ctx.Diags.diagnose(limitImport->importLoc,
diag::decl_import_via_here, ext,
limitImport->accessLevel,
limitImport->module.importedModule);
limitImport->module.importedModule,
limitImport->module.importedModule
->isClangHeaderImportModule());
}
return true;

View File

@@ -461,7 +461,9 @@ static void noteLimitingImport(const Decl *userDecl, ASTContext &ctx,
if (limitImport->importLoc.isValid())
ctx.Diags.diagnose(limitImport->importLoc, diag::decl_import_via_here,
complainDecl, limitImport->accessLevel,
limitImport->module.importedModule);
limitImport->module.importedModule,
limitImport->module.importedModule
->isClangHeaderImportModule());
} else if (limitImport->importLoc.isValid()) {
ctx.Diags.diagnose(limitImport->importLoc, diag::module_imported_here,
limitImport->module.importedModule,

View File

@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t/tmp
// Test with the normal bridging header.
// RUN: %target-typecheck-verify-swift -internal-import-bridging-header %S/../Inputs/c-bridging-header.h -sdk %clang-importer-sdk -verify-ignore-unknown
// RUN: not %target-swift-frontend -typecheck -internal-import-bridging-header %S/../Inputs/c-bridging-header.h -sdk %clang-importer-sdk %s 2>&1 | %FileCheck %s
// Test with a precompiled bridging header.
// RUN: %target-swift-frontend -emit-pch -o %t/c-bridging-header.pch %S/../Inputs/c-bridging-header.h -sdk %clang-importer-sdk
// RUN: %target-typecheck-verify-swift -internal-import-bridging-header %t/c-bridging-header.pch -sdk %clang-importer-sdk -verify-ignore-unknown
@inlinable
public func f() -> Any {
return red
// expected-error@-1{{var 'red' is internal and cannot be referenced from an '@inlinable' function}}
// expected-warning@-2{{getter for var 'red' is internal and should not be referenced from an '@inlinable' function}}
}
// CHECK: var 'red' imported as 'internal' from bridging header