<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">That seems to be a known problem: <a href="https://bugs.swift.org/browse/SR-773" class="">https://bugs.swift.org/browse/SR-773</a> <div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 29. Apr 2017, at 22:38, Nevin Brackett-Rozinsky via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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:<div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class="">protocol P {</font></div><div class=""><font face="monospace, monospace" class=""> associatedtype C: Collection</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">extension P {</font></div><div class=""><font face="monospace, monospace" class=""> func emptyArray() -> [C.Iterator.Element] {</font></div><div class=""><font face="monospace, monospace" class=""> return [C.Iterator.Element]() // Error</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class="">}</font></div></div><div class=""><br class=""></div><div class="">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:</div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class="">extension P {</font></div><div class=""><font face="monospace, monospace" class=""> func emptyArray() -> [C.Iterator.Element] {</font></div><div class=""><font face="monospace, monospace" class=""> typealias E = C.Iterator.Element</font></div><div class=""><font face="monospace, monospace" class=""> return [E]() // Works</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class="">}</font></div></div><div class=""><br class=""></div><div class="">Is this a known bug?</div><div class=""><br class=""></div><div class="">Nevin</div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>