Skip to content

Commit b7353c9

Browse files
committed
[Sema] Force reporting public imports of private module as error with asserts
When running in assert mode make it an error for a public module to publicly import a private module.
1 parent b1eb438 commit b7353c9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
17761776
}
17771777

17781778
static bool treatAsError = getenv("ENABLE_PUBLIC_IMPORT_OF_PRIVATE_AS_ERROR");
1779+
#ifndef NDEBUG
1780+
treatAsError = true;
1781+
#endif
17791782
if (!treatAsError)
17801783
inFlight.limitBehavior(DiagnosticBehavior::Warning);
17811784
}

test/Sema/implementation-only-import-suggestion.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
// RUN: -library-level other -D PUBLIC_IMPORTS
3535
#if PUBLIC_IMPORTS
3636
import PublicSwift
37-
import PrivateSwift // expected-warning{{private module 'PrivateSwift' is imported publicly from the public module 'main'}}
37+
import PrivateSwift // expected-error{{private module 'PrivateSwift' is imported publicly from the public module 'main'}}
3838

3939
import PublicClang
40-
import PublicClang_Private // expected-warning{{private module 'PublicClang_Private' is imported publicly from the public module 'main'}}
41-
import FullyPrivateClang // expected-warning{{private module 'FullyPrivateClang' is imported publicly from the public module 'main'}}
40+
import PublicClang_Private // expected-error{{private module 'PublicClang_Private' is imported publicly from the public module 'main'}}
41+
import FullyPrivateClang // expected-error{{private module 'FullyPrivateClang' is imported publicly from the public module 'main'}}
4242
import main // expected-warning{{'implementation-only-import-suggestion.swift' is part of module 'main'; ignoring import}}
4343

4444
/// Expect no warnings with implementation-only imports.

0 commit comments

Comments
 (0)