Skip to content

Commit 33db186

Browse files
committed
[Sema] Always accept access-level on imports in swiftinterface
While use of access-level in imports is still gated by a flag for normal source code, accept it in swiftinterfaces without the flag. This will make it easier for older compilers to read newer swiftinterfaces created by a future compiler where that restriction is lifted. rdar://115455383
1 parent 5b8553c commit 33db186

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,8 @@ void AttributeChecker::visitLazyAttr(LazyAttr *attr) {
968968

969969
bool AttributeChecker::visitAbstractAccessControlAttr(
970970
AbstractAccessControlAttr *attr) {
971-
// Access control attr may only be used on value decls and extensions.
971+
// Access control attr may only be used on value decls, extensions and
972+
// imports.
972973
if (!isa<ValueDecl>(D) && !isa<ExtensionDecl>(D) && !isa<ImportDecl>(D)) {
973974
diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr);
974975
return true;
@@ -996,7 +997,9 @@ bool AttributeChecker::visitAbstractAccessControlAttr(
996997
}
997998

998999
if (auto importDecl = dyn_cast<ImportDecl>(D)) {
999-
if (!D->getASTContext().LangOpts.hasFeature(Feature::AccessLevelOnImport)) {
1000+
SourceFile *File = D->getDeclContext()->getParentSourceFile();
1001+
if (!D->getASTContext().LangOpts.hasFeature(Feature::AccessLevelOnImport) &&
1002+
File && File->Kind != SourceFileKind::Interface) {
10001003
diagnoseAndRemoveAttr(attr, diag::access_level_on_import_not_enabled);
10011004
return true;
10021005
}

test/Sema/access-level-import-flag-check.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// RUN: -package-name package
1717
// REQUIRES: asserts
1818

19+
/// swiftinterfaces don't need the flag.
20+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface)
21+
1922
//--- PublicLib.swift
2023
//--- PackageLib.swift
2124
//--- InternalLib.swift
@@ -28,3 +31,8 @@ package import PackageLib // expected-error@:1 {{Access level on imports require
2831
internal import InternalLib // expected-error@:1 {{Access level on imports require '-enable-experimental-feature AccessLevelOnImport'}}
2932
fileprivate import FileprivateLib // expected-error@:1 {{Access level on imports require '-enable-experimental-feature AccessLevelOnImport'}}
3033
private import PrivateLib // expected-error@:1 {{Access level on imports require '-enable-experimental-feature AccessLevelOnImport'}}
34+
35+
//--- Client.swiftinterface
36+
// swift-interface-format-version: 1.0
37+
// swift-module-flags: -enable-library-evolution
38+
public import Swift

0 commit comments

Comments
 (0)