mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
A keypath using dynamic member lookup results in various `KeyPathExpr` that have components with no location. Ignore these and any other references that have a missing location. Resolves rdar://85237365
37 lines
679 B
Swift
37 lines
679 B
Swift
struct Point {
|
|
var x: Int
|
|
var y: Int
|
|
}
|
|
|
|
struct Rectangle {
|
|
var topLeft: Point
|
|
var bottomRight: Point
|
|
}
|
|
|
|
@dynamicMemberLookup
|
|
struct Lens<T> {
|
|
var obj: T
|
|
init(_ obj: T) {
|
|
self.obj = obj
|
|
}
|
|
|
|
subscript<U>(dynamicMember member: WritableKeyPath<T, U>) -> Lens<U> {
|
|
get { return Lens<U>(obj[keyPath: member]) }
|
|
set { obj[keyPath: member] = newValue.obj }
|
|
}
|
|
}
|
|
|
|
func test(r: Lens<Rectangle>) {
|
|
_ = r.topLeft
|
|
_ = r.bottomRight.y
|
|
}
|
|
|
|
func keyPathTester<V>(keyPath: KeyPath<Lens<Rectangle>, V>) {}
|
|
|
|
func testKeyPath() {
|
|
keyPathTester(keyPath: \.topLeft)
|
|
}
|
|
|
|
// RUN: %sourcekitd-test -req=sema %s -- %s > %t.response
|
|
// RUN: %diff -u %s.response %t.response
|