Skip to content

Commit db19c19

Browse files
committed
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.
1 parent 8651af4 commit db19c19

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

include/swift/AST/LookupKinds.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ enum NLOptions : unsigned {
4141

4242
/// Don't check access when doing lookup into a type.
4343
///
44-
/// This option is not valid when performing lookup into a module.
44+
/// When performing lookup into a module, this option only applies to
45+
/// declarations in the same module the lookup is coming from.
4546
NL_IgnoreAccessControl = 1 << 3,
4647

4748
/// This lookup should only return type declarations.

lib/AST/ModuleNameLookup.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
165165
if (resolutionKind == ResolutionKind::MacrosOnly && !isa<MacroDecl>(VD))
166166
return true;
167167
if (respectAccessControl &&
168+
// NL_IgnoreAccessControl applies only to the current module.
169+
!((options & NL_IgnoreAccessControl) &&
170+
moduleScopeContext &&
171+
moduleScopeContext->getParentModule() ==
172+
VD->getDeclContext()->getParentModule()) &&
168173
!VD->isAccessibleFrom(moduleScopeContext, false,
169174
includeUsableFromInline))
170175
return true;

test/NameLookup/Inputs/accessibility_other.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import has_accessibility
22

33
public let a = 0 // expected-note * {{did you mean 'a'?}}
44
internal let b = 0 // expected-note * {{did you mean 'b'?}}
5-
private let c = 0
5+
private let c = 0 // expected-note {{'c' declared here}}
66

77
extension Foo {
88
public static func a() {}

test/NameLookup/accessibility.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ markUsed(has_accessibility.z) // expected-error {{module 'has_accessibility' has
2626

2727
markUsed(accessibility.a)
2828
markUsed(accessibility.b)
29-
markUsed(accessibility.c) // expected-error {{module 'accessibility' has no member named 'c'}}
29+
markUsed(accessibility.c) // expected-error {{'c' is inaccessible due to 'private' protection level}}
3030

3131
markUsed(x)
3232
markUsed(y) // expected-error {{cannot find 'y' in scope}}

0 commit comments

Comments
 (0)