mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Let module lookups ignore access control
…at least for declarations in the current module. We continue to pretend that inaccessible declarations in other modules do not exist.
This commit is contained in:
@@ -41,7 +41,8 @@ enum NLOptions : unsigned {
|
||||
|
||||
/// Don't check access when doing lookup into a type.
|
||||
///
|
||||
/// This option is not valid when performing lookup into a module.
|
||||
/// When performing lookup into a module, this option only applies to
|
||||
/// declarations in the same module the lookup is coming from.
|
||||
NL_IgnoreAccessControl = 1 << 3,
|
||||
|
||||
/// This lookup should only return type declarations.
|
||||
|
||||
@@ -165,6 +165,11 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
|
||||
if (resolutionKind == ResolutionKind::MacrosOnly && !isa<MacroDecl>(VD))
|
||||
return true;
|
||||
if (respectAccessControl &&
|
||||
// NL_IgnoreAccessControl applies only to the current module.
|
||||
!((options & NL_IgnoreAccessControl) &&
|
||||
moduleScopeContext &&
|
||||
moduleScopeContext->getParentModule() ==
|
||||
VD->getDeclContext()->getParentModule()) &&
|
||||
!VD->isAccessibleFrom(moduleScopeContext, false,
|
||||
includeUsableFromInline))
|
||||
return true;
|
||||
|
||||
@@ -2,7 +2,7 @@ import has_accessibility
|
||||
|
||||
public let a = 0 // expected-note * {{did you mean 'a'?}}
|
||||
internal let b = 0 // expected-note * {{did you mean 'b'?}}
|
||||
private let c = 0
|
||||
private let c = 0 // expected-note {{'c' declared here}}
|
||||
|
||||
extension Foo {
|
||||
public static func a() {}
|
||||
|
||||
@@ -26,7 +26,7 @@ markUsed(has_accessibility.z) // expected-error {{module 'has_accessibility' has
|
||||
|
||||
markUsed(accessibility.a)
|
||||
markUsed(accessibility.b)
|
||||
markUsed(accessibility.c) // expected-error {{module 'accessibility' has no member named 'c'}}
|
||||
markUsed(accessibility.c) // expected-error {{'c' is inaccessible due to 'private' protection level}}
|
||||
|
||||
markUsed(x)
|
||||
markUsed(y) // expected-error {{cannot find 'y' in scope}}
|
||||
|
||||
Reference in New Issue
Block a user