Skip to content

[5.3] Fix dynamic member lookup index-while-building crash #32168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ void ConstraintSystem::bindOverloadType(

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

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

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

// The resolved decl is for subscript(dynamicMember:), however the
Expand Down
21 changes: 21 additions & 0 deletions test/Index/index_keypath_member_lookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,24 @@ func testExplicit(r: Lens<Rectangle>, a: Lens<[Int]>) {
// CHECK: [[EA_LINE]]:8 | instance-property/subscript/Swift | subscript(dynamicMember:) | [[SUB_USR]] | Ref,Read,RelCont | rel: 1
// CHECK: [[EA_LINE]]:26 | instance-property/subscript/Swift | subscript(_:) | s:SayxSicip | Ref,Read,RelCont | rel: 1
}

// Don't crash: rdar63558609
//
@dynamicMemberLookup
protocol Foo {
var prop: Bar {get}
// CHECK: [[@LINE-1]]:7 | instance-property/Swift | prop | [[PROP_USR:.*]] | Def,RelChild | rel: 1
}
struct Bar {
let enabled = false
}
extension Foo {
subscript<T>(dynamicMember keyPath: KeyPath<Bar,T>) -> T {
// CHECK: [[@LINE-1]]:3 | instance-property/subscript/Swift | subscript(dynamicMember:) | [[SUB2_USR:.*]] | Def,RelChild | rel: 1
// CHECK: [[@LINE-2]]:60 | instance-method/acc-get/Swift | getter:subscript(dynamicMember:) | {{.*}} | Def,Dyn,RelChild,RelAcc | rel: 1
// CHECK-NEXT: RelChild,RelAcc | instance-property/subscript/Swift | subscript(dynamicMember:) | [[SUB2_USR]]

prop[keyPath: keyPath]
// CHECK: [[@LINE-1]]:5 | instance-property/Swift | prop | [[PROP_USR]] | Ref,Read,RelCont | rel: 1
}
}