Skip to content

Commit 4d8e612

Browse files
committed
[CS] Prevent callAsFunction from being used on AnyObject
Previously this hit an assertion in CSApply. While we could technically make it work, it's probably best not to allow it. Resolves SR-11829.
1 parent bf0e9c7 commit 4d8e612

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/AST/Type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,10 @@ bool TypeBase::satisfiesClassConstraint() {
14811481
}
14821482

14831483
bool TypeBase::isCallableNominalType(DeclContext *dc) {
1484+
// Don't allow callAsFunction to be used with dynamic lookup.
1485+
if (isAnyObject())
1486+
return false;
1487+
14841488
// If the type cannot have members, we're done.
14851489
if (!mayHaveMembers())
14861490
return false;

test/Constraints/dynamic_lookup.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,13 @@ class HasMethodWithDefault {
398398
func testAnyObjectWithDefault(_ x: AnyObject) {
399399
x.hasDefaultParam()
400400
}
401+
402+
// SR-11829: Don't perform dynamic lookup for callAsFunction.
403+
class ClassWithObjcCallAsFunction {
404+
@objc func callAsFunction() {}
405+
}
406+
407+
func testCallAsFunctionAnyObject(_ x: AnyObject) {
408+
x() // expected-error {{cannot call value of non-function type 'AnyObject'}}
409+
x.callAsFunction() // Okay.
410+
}

0 commit comments

Comments
 (0)