[swift-users] Error creating empty array of chained associated type

Martin R martinr448 at gmail.com
Sat Apr 29 15:45:09 CDT 2017


That seems to be a known problem: https://bugs.swift.org/browse/SR-773 <https://bugs.swift.org/browse/SR-773> 

> On 29. Apr 2017, at 22:38, Nevin Brackett-Rozinsky via swift-users <swift-users at swift.org> wrote:
> 
> 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
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170429/95f10b77/attachment.html>


More information about the swift-users mailing list