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:
Becca Royal-Gordon
2023-11-02 13:54:49 -07:00
parent 8651af4325
commit db19c19e19
4 changed files with 9 additions and 3 deletions

View File

@@ -41,7 +41,8 @@ enum NLOptions : unsigned {
/// Don't check access when doing lookup into a type. /// 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, NL_IgnoreAccessControl = 1 << 3,
/// This lookup should only return type declarations. /// This lookup should only return type declarations.

View File

@@ -165,6 +165,11 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
if (resolutionKind == ResolutionKind::MacrosOnly && !isa<MacroDecl>(VD)) if (resolutionKind == ResolutionKind::MacrosOnly && !isa<MacroDecl>(VD))
return true; return true;
if (respectAccessControl && if (respectAccessControl &&
// NL_IgnoreAccessControl applies only to the current module.
!((options & NL_IgnoreAccessControl) &&
moduleScopeContext &&
moduleScopeContext->getParentModule() ==
VD->getDeclContext()->getParentModule()) &&
!VD->isAccessibleFrom(moduleScopeContext, false, !VD->isAccessibleFrom(moduleScopeContext, false,
includeUsableFromInline)) includeUsableFromInline))
return true; return true;

View File

@@ -2,7 +2,7 @@ import has_accessibility
public let a = 0 // expected-note * {{did you mean 'a'?}} public let a = 0 // expected-note * {{did you mean 'a'?}}
internal let b = 0 // expected-note * {{did you mean 'b'?}} 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 { extension Foo {
public static func a() {} public static func a() {}

View File

@@ -26,7 +26,7 @@ markUsed(has_accessibility.z) // expected-error {{module 'has_accessibility' has
markUsed(accessibility.a) markUsed(accessibility.a)
markUsed(accessibility.b) 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(x)
markUsed(y) // expected-error {{cannot find 'y' in scope}} markUsed(y) // expected-error {{cannot find 'y' in scope}}