![](/img/trans.png)
[英]Why can't you use @autoclosure on a typealias to a function closure type?
[英]Why can’t you use a generic Self reference in a Swift 3.2/4 KeyPath typealias?
為什么在Swift 3.2 / 4 KeyPath typealias中不能使用通用的Self引用?
示例:除非取消注釋標記為// B
的行,否則下面的代碼將編譯。 為什么? 據我typealias Path<T> = KeyPath<Self,T>
,由於語句typealias Path<T> = KeyPath<Self,T>
標記// B
的行應與標記// A
的行完全相同。
我在這里錯過了什么嗎,或者這是Swift編譯器的錯誤?
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
}
要聲明密鑰路徑,需要在尖括號內的根,密鑰路徑的值。 就像在Swift中用類型聲明Array一樣。 這應該工作:
var fooerPathB: F.Path<F, T> { get set }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.