Skip to content

Commit 797839f

Browse files
authored
Merge pull request #23497 from theblixguy/fix/SR-10146
[CSApply] Fix a KeyPath crash in SIL when base type is AnyObject
2 parents 86888ce + 676d914 commit 797839f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4184,7 +4184,16 @@ namespace {
41844184
auto keyPathTy = cs.getType(E)->castTo<BoundGenericType>();
41854185
Type baseTy = keyPathTy->getGenericArgs()[0];
41864186
Type leafTy = keyPathTy->getGenericArgs()[1];
4187-
4187+
4188+
// We do not allow keypaths to go through AnyObject
4189+
if (baseTy->isAnyObject()) {
4190+
auto rootTyRepr = E->getRootType();
4191+
cs.TC.diagnose(rootTyRepr->getLoc(),
4192+
diag::expr_swift_keypath_invalid_component)
4193+
.highlight(rootTyRepr->getSourceRange());
4194+
return nullptr;
4195+
}
4196+
41884197
for (unsigned i : indices(E->getComponents())) {
41894198
auto &origComponent = E->getMutableComponents()[i];
41904199

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: not %target-swift-frontend -emit-sil %s
2+
// REQUIRES: OS=ios
3+
4+
import UIKit
5+
6+
// Just make sure we don't crash.
7+
8+
class Foo: NSObject {
9+
func crash() {
10+
let kp = \AnyObject.accessibilityFrame
11+
}
12+
}

0 commit comments

Comments
 (0)