Skip to content

Commit b5bf217

Browse files
authored
Merge pull request #77538 from xymus/dont-warn-submodules-reexport
Sema: fix reporting reexporting submodules imports as unused in API
2 parents 4a909c7 + a4fcdef commit b5bf217

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,8 +2517,11 @@ void swift::recordRequiredImportAccessLevelForDecl(
25172517
if (auto attributedImport = sf->getImportAccessLevel(definingModule)) {
25182518
auto importedModule = attributedImport->module.importedModule;
25192519

2520-
// If the defining module is transitively imported, mark the responsible
2521-
// module as requiring the minimum access level too.
2520+
// Ignore submodules, same behavior from `getModuleContext` above.
2521+
importedModule = importedModule->getTopLevelModule();
2522+
2523+
// If the defining module is transitively imported, mark the locally
2524+
// imported module as requiring the minimum access level too.
25222525
if (importedModule != definingModule)
25232526
sf->registerRequiredAccessLevelForModule(importedModule, accessLevel);
25242527

test/Sema/superfluously-public-imports.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
// RUN: %target-swift-frontend -typecheck %t/ClientOfClangModules.swift -I %t \
3333
// RUN: -package-name pkg -Rmodule-api-import \
3434
// RUN: -enable-upcoming-feature InternalImportsByDefault -verify
35+
// RUN: %target-swift-frontend -typecheck %t/ClientOfClangReexportedSubmodules.swift -I %t \
36+
// RUN: -package-name pkg -Rmodule-api-import \
37+
// RUN: -enable-upcoming-feature InternalImportsByDefault -verify
3538
// RUN: %target-swift-frontend -typecheck %t/Client_Swift5.swift -I %t \
3639
// RUN: -swift-version 5 -verify
3740

@@ -285,6 +288,21 @@ module ClangTopModule {
285288
}
286289
}
287290

291+
module ClangReexportedSubmodulePublic {
292+
header "ClangReexportedSubmodulePublic.h"
293+
module ClangReexportedSubmodulePublicSub {
294+
header "ClangReexportedSubmodulePublicSub.h"
295+
export *
296+
}
297+
}
298+
299+
module ClangReexportedSubmoduleTop {
300+
header "ClangReexportedSubmoduleTop.h"
301+
module ClangReexportedSubmoduleSub {
302+
header "ClangReexportedSubmoduleSub.h"
303+
}
304+
}
305+
288306
//--- ClangSimpleUnused.h
289307
//--- ClangSimple.h
290308
struct ClangSimpleType {};
@@ -300,6 +318,15 @@ struct ClangSubmoduleSubmoduleType {};
300318
struct ClangTopModuleType {};
301319
//--- ClangTopModuleSubmodule.h
302320

321+
//--- ClangReexportedSubmodulePublic.h
322+
//--- ClangReexportedSubmodulePublicSub.h
323+
#include <ClangReexportedSubmoduleSub.h>
324+
325+
//--- ClangReexportedSubmoduleTop.h
326+
//--- ClangReexportedSubmoduleSub.h
327+
typedef struct _TypedefTypeUnderlying {
328+
} TypedefType;
329+
303330
//--- ClientOfClangModules.swift
304331
public import ClangSimple
305332
public import ClangSimpleUnused // expected-warning {{public import of 'ClangSimpleUnused' was not used in public declarations or inlinable code}}
@@ -312,3 +339,9 @@ public import ClangTopModule.ClangTopModuleSubmodule
312339
public func clangUser(a: ClangSimpleType) {} // expected-remark {{struct 'ClangSimpleType' is imported via 'ClangSimple'}}
313340
public func clangUser(a: ClangSubmoduleSubmoduleType) {} // expected-remark {{struct 'ClangSubmoduleSubmoduleType' is imported via 'ClangSubmodule'}}
314341
public func clangUser(a: ClangTopModuleType) {} // expected-remark {{struct 'ClangTopModuleType' is imported via 'ClangTopModule'}}
342+
343+
//--- ClientOfClangReexportedSubmodules.swift
344+
public import ClangReexportedSubmodulePublic.ClangReexportedSubmodulePublicSub
345+
346+
public func useTypedefed(a: TypedefType) {} // expected-remark 2 {{typealias underlying type struct '_TypedefTypeUnderlying' is imported via 'ClangReexportedSubmodulePublicSub', which reexports definition from 'ClangReexportedSubmoduleTop'}}
347+
// expected-remark @-1 {{type alias 'TypedefType' is imported via 'ClangReexportedSubmodulePublicSub', which reexports definition from 'ClangReexportedSubmoduleTop'}}

0 commit comments

Comments
 (0)