Skip to content

Commit adf712e

Browse files
authored
Merge pull request #40364 from xymus/error-on-import-of-private-in-assert
[Sema] Report public imports of private module as error in asserts mode
2 parents 79bb32d + 5f2ce69 commit adf712e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: lib/Sema/TypeCheckDeclPrimary.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
17711771
}
17721772

17731773
static bool treatAsError = getenv("ENABLE_PUBLIC_IMPORT_OF_PRIVATE_AS_ERROR");
1774+
#ifndef NDEBUG
1775+
treatAsError = true;
1776+
#endif
17741777
if (!treatAsError)
17751778
inFlight.limitBehavior(DiagnosticBehavior::Warning);
17761779
}

Diff for: test/Sema/implementation-only-import-suggestion.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// REQUIRES: VENDOR=apple
3+
// REQUIRES: asserts
34

45
/// Prepare the SDK.
56
// RUN: cp -r %S/Inputs/public-private-sdk %t/sdk
@@ -34,11 +35,11 @@
3435
// RUN: -library-level other -D PUBLIC_IMPORTS
3536
#if PUBLIC_IMPORTS
3637
import PublicSwift
37-
import PrivateSwift // expected-warning{{private module 'PrivateSwift' is imported publicly from the public module 'main'}}
38+
import PrivateSwift // expected-error{{private module 'PrivateSwift' is imported publicly from the public module 'main'}}
3839

3940
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'}}
41+
import PublicClang_Private // expected-error{{private module 'PublicClang_Private' is imported publicly from the public module 'main'}}
42+
import FullyPrivateClang // expected-error{{private module 'FullyPrivateClang' is imported publicly from the public module 'main'}}
4243
import main // expected-warning{{'implementation-only-import-suggestion.swift' is part of module 'main'; ignoring import}}
4344

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

0 commit comments

Comments
 (0)