Skip to content

Commit c319763

Browse files
committed
[Name lookup] Filter declarations found via dynamic lookup based on accessibility.
1 parent 52b961d commit c319763

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,8 @@ bool DeclContext::lookupQualified(Type type,
13241324

13251325
// If we didn't visit this nominal type above, add this
13261326
// declaration to the list.
1327-
if (!visited.count(nominal) && knownDecls.insert(decl).second)
1327+
if (!visited.count(nominal) && knownDecls.insert(decl).second &&
1328+
isAcceptableDecl(nominal, decl))
13281329
decls.push_back(decl);
13291330
}
13301331
}

test/Constraints/dynamic_lookup.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// RUN: %target-parse-verify-swift
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/PrivateObjC.swift -o %t
3+
// RUN: %target-parse-verify-swift -I %t
24

35
// REQUIRES: objc_interop
46
import Foundation
7+
import PrivateObjC
58

69
@objc
710
class A {
@@ -212,3 +215,7 @@ var obj3 : AnyObject = (p as! AnyObject)! // expected-error{{cannot force unwrap
212215
// Implicit force of an implicitly unwrapped optional
213216
let uopt : AnyObject! = nil
214217
uopt.wibble!()
218+
219+
// Should not be able to see private or internal @objc methods.
220+
uopt.privateFoo!() // expected-error{{'privateFoo' is inaccessible due to 'private' protection level}}
221+
uopt.internalFoo!() // expected-error{{'internalFoo' is inaccessible due to 'internal' protection level}}

0 commit comments

Comments
 (0)