I’ve stumbled upon an odd situation where Swift gives a compiler error if I
do things directly, but works properly with no error if I first create a
typealias. Here is a stripped-down example:
protocol P {
associatedtype C: Collection
}
extension P {
func emptyArray() -> [C.Iterator.Element] {
return [C.Iterator.Element]() // Error
}
}
The “return” line gives the error “Cannot call value of non-function type
'[Self.C.Iterator.Element.Type]'” in Xcode 8.3.2. However, if we replace
that function with a seemingly-equivalent version that uses a typealias,
there is no error:
extension P {
func emptyArray() -> [C.Iterator.Element] {
typealias E = C.Iterator.Element
return [E]() // Works
}
}
Is this a known bug?
Nevin
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users