<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="">Hi Ryan,<div class=""><br class=""></div><div class="">Are you sure it works with user-defined struct types? I tried the following code, and got the same error:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span> MyProtocol {}</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> Blah : <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyProtocol</span> { }</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> foo() -> [<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyProtocol</span>] {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> a = [<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Blah</span>(), <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Blah</span>()] <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span> [<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Blah</span>]</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>return<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> a</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">'class Blah' works fine.</div><div class=""><br class=""></div><div class="">Even so, this is not the behavior I would have expected. Perhaps someone else can explain why [T] can't be upcasted to [P] when T is a struct and T : P.</div><div class=""><br class=""></div><div class="">Best,</div><div class="">Austin</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 25, 2016, at 7:36 PM, Ryan Walklin 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi All,<div class=""><br class=""></div><div class="">I have a function which returns a closure, which then returns an array of objects conforming to a protocol. </div><div class=""><br class=""></div><div class="">ie. </div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Courier; color: rgb(16, 16, 16);" class="">protocol MyProtocol {}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Courier; color: rgb(16, 16, 16); min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Courier; color: rgb(16, 16, 16);" class="">extension Float: MyProtocol {}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Courier; color: rgb(16, 16, 16);" class="">extension OtherType: MyProtocol {}</div></div><div class=""><br class=""></div><div class="">When I try to return an array of Floats, I get the error “Cannot convert value of type '[Float]' to closure result type ‘[MyProtocol]”.</div><div class=""><br class=""></div><div class="">Other struct-based types work fine.</div><div class=""><br class=""></div><div class="">Is this not possible with standard library types?</div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><br class=""></div><div class="">Ryan</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>