[CS] Do member lookup last when binding dynamic member overload

Otherwise if the member lookup gets simplified immediately and we 
have a recursive dynamic member lookup we will crash since we wouldn't
have introduced the corresponding applicable function constraint.

rdar://164321858
This commit is contained in:
Hamish Knight
2025-12-12 15:57:54 +00:00
parent 22d182552c
commit 4b25dc528d
2 changed files with 66 additions and 27 deletions

View File

@@ -616,3 +616,39 @@ class TestDynamicSelf {
fatalError()
}
}
@dynamicMemberLookup
protocol P1 {}
extension P1 {
subscript<T>(dynamicMember dynamicMemberLookup: KeyPath<TestOverloaded.S2, T>) -> T {
fatalError()
}
}
struct TestOverloaded {
struct S1: P1 {
subscript(x: String) -> Int {
fatalError()
}
func f(_ x: String) -> Int {
return self[x]
}
}
struct S2: P1 {}
}
@dynamicMemberLookup
struct SingleLens<T> {
var value: T
init(_ value: T) {
self.value = value
}
subscript<U>(dynamicMember keyPath: KeyPath<T, U>) -> U {
value[keyPath: keyPath]
}
}
func testRecursiveSingleSubscript(_ x: SingleLens<SingleLens<SingleLens<SingleLens<[Int]>>>>) {
_ = x[0]
}