Why can't you use a generic Self reference in a Swift 3.2/4 KeyPath typealias?
Example: the below code compiles unless you uncomment the line marked // B
. Why? From what I can reason, the line marked // B
should mean exactly the same thing as the line marked // A
, due to the statement typealias Path<T> = KeyPath<Self,T>
.
Am I missing something here, or is this a Swift compiler bug?
protocol Fooer {
associatedtype T
typealias Path<T> = KeyPath<Self, T>
var baz: T { get }
}
protocol FooPathContainable {
associatedtype F: Fooer
associatedtype T where F.T == T
var fooerPathA: KeyPath<F,T> { get set } // A
var fooerPathB: F.Path<T> { get set } // B <— causes compiler crash with Segmentation Fault 11
}
root, value of keypath, inside angular brackets, is required to declare a keypath. It is like declaring Array with type in Swift. This should work:
var fooerPathB: F.Path<F, T> { get set }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.