Skip to content

Commit edf8c20

Browse files
authored
Merge pull request #32168 from nathawes/dynamic-member-lookup-indexing-crash
[5.3] Fix dynamic member lookup index-while-building crash
2 parents d831670 + 851f372 commit edf8c20

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ void ConstraintSystem::bindOverloadType(
20622062

20632063
// If this is used inside of the keypath expression, we need to make
20642064
// sure that argument is Hashable.
2065-
if (isa<KeyPathExpr>(locator->getAnchor()))
2065+
if (llvm::isa_and_nonnull<KeyPathExpr>(locator->getAnchor()))
20662066
verifyThatArgumentIsHashable(0, argType, locator);
20672067

20682068
// The resolved decl is for subscript(dynamicMember:), however the original
@@ -2184,7 +2184,7 @@ void ConstraintSystem::bindOverloadType(
21842184
addConstraint(ConstraintKind::Equal, memberTy, leafTy, keyPathLoc);
21852185
}
21862186

2187-
if (isa<KeyPathExpr>(locator->getAnchor()))
2187+
if (llvm::isa_and_nonnull<KeyPathExpr>(locator->getAnchor()))
21882188
verifyThatArgumentIsHashable(0, keyPathTy, locator);
21892189

21902190
// The resolved decl is for subscript(dynamicMember:), however the

test/Index/index_keypath_member_lookup.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,24 @@ func testExplicit(r: Lens<Rectangle>, a: Lens<[Int]>) {
137137
// CHECK: [[EA_LINE]]:8 | instance-property/subscript/Swift | subscript(dynamicMember:) | [[SUB_USR]] | Ref,Read,RelCont | rel: 1
138138
// CHECK: [[EA_LINE]]:26 | instance-property/subscript/Swift | subscript(_:) | s:SayxSicip | Ref,Read,RelCont | rel: 1
139139
}
140+
141+
// Don't crash: rdar63558609
142+
//
143+
@dynamicMemberLookup
144+
protocol Foo {
145+
var prop: Bar {get}
146+
// CHECK: [[@LINE-1]]:7 | instance-property/Swift | prop | [[PROP_USR:.*]] | Def,RelChild | rel: 1
147+
}
148+
struct Bar {
149+
let enabled = false
150+
}
151+
extension Foo {
152+
subscript<T>(dynamicMember keyPath: KeyPath<Bar,T>) -> T {
153+
// CHECK: [[@LINE-1]]:3 | instance-property/subscript/Swift | subscript(dynamicMember:) | [[SUB2_USR:.*]] | Def,RelChild | rel: 1
154+
// CHECK: [[@LINE-2]]:60 | instance-method/acc-get/Swift | getter:subscript(dynamicMember:) | {{.*}} | Def,Dyn,RelChild,RelAcc | rel: 1
155+
// CHECK-NEXT: RelChild,RelAcc | instance-property/subscript/Swift | subscript(dynamicMember:) | [[SUB2_USR]]
156+
157+
prop[keyPath: keyPath]
158+
// CHECK: [[@LINE-1]]:5 | instance-property/Swift | prop | [[PROP_USR]] | Ref,Read,RelCont | rel: 1
159+
}
160+
}

0 commit comments

Comments
 (0)