Files
swift-mirror/test/SourceKit/Sema/sema_dynamic_keypath.swift
Ben Barham f6db91e3f9 [SourceKit] Ignore references without a location
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
2021-11-10 14:52:46 +10:00

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