Skip to content

Commit 2d7a088

Browse files
committed
Don't check access control for isCallableNominalType
We still want the constraint system to try looking up a callAsFunction method even if it's inaccessible, as we'll be able to record a fix and emit a suitable diagnostic.
1 parent aa8d7ba commit 2d7a088

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

include/swift/AST/Types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@ class alignas(1 << TypeAlignInBits) TypeBase {
819819
}
820820

821821
/// Checks whether this is a type that supports being called through the
822-
/// implementation of a \c callAsFunction method.
822+
/// implementation of a \c callAsFunction method. Note that this does not
823+
/// check access control.
823824
bool isCallableNominalType(DeclContext *dc);
824825

825826
/// Retrieve the superclass of this type.

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4575,6 +4575,7 @@ llvm::Expected<bool>
45754575
IsCallableNominalTypeRequest::evaluate(Evaluator &evaluator, CanType ty,
45764576
DeclContext *dc) const {
45774577
auto options = defaultMemberLookupOptions;
4578+
options |= NameLookupFlags::IgnoreAccessControl;
45784579
if (isa<AbstractFunctionDecl>(dc))
45794580
options |= NameLookupFlags::KnownPrivate;
45804581

test/Sema/call_as_function_simple.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,12 @@ func testIUOCallAsFunction(_ x: IUOCallable) {
219219
let _: IUOCallable = .callable(5)
220220
let _: IUOCallable? = .callable(5)
221221
}
222+
223+
// Test access control.
224+
struct PrivateCallable {
225+
private func callAsFunction(_ x: Int) {} // expected-note {{'callAsFunction' declared here}}
226+
}
227+
228+
func testAccessControl(_ x: PrivateCallable) {
229+
x(5) // expected-error {{'callAsFunction' is inaccessible due to 'private' protection level}}
230+
}

0 commit comments

Comments
 (0)