<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">You protocol is not defined properly.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 21, 2016 at 7:08 AM, Howard Lovatt via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">HI,<div><br></div><div>Does anyone know what is happening here:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p>protocol Subscriptable {</p></div><div><p>    associatedtype Element</p></div><div><p>    associatedtype Index</p></div><div><p>    var firstIndex: Index { get }</p></div><div><p>    var lastIndex: Index { get }</p></div><div><p>    subscript(index: Index) -&gt; Element { get set }</p></div><div><p>}</p></div><div><p><br></p></div><div><p>struct AllSubscriptable&lt;E, I&gt;: Subscriptable {</p></div><div><p>    typealias Element = E</p></div><div><p>    typealias Index = I</p></div><div><p>    let firstIndexee: () -&gt; I</p></div><div><p>    let lastIndexee: () -&gt; I</p></div><div><p>    let subscriptee: (index: I) -&gt; E</p></div><div><p>    let setSubscriptee: (index: I, element: E) -&gt; Void</p></div><div><p>    var firstIndex: I { return firstIndexee() }</p></div><div><p>    var lastIndex: I { return lastIndexee() }</p></div><div><p>    subscript(index: I) -&gt; E {</p></div><div><p>        get { return subscriptee(index: index) }</p></div><div><p>        set { setSubscriptee(index: index, element: newValue) }</p></div><div><p>    }</p></div><div><p>}</p></div><div><p><br></p></div><div><p>extension Array {</p></div><div><p>    var asScriptable: AllSubscriptable&lt;Element, Int&gt; {</p></div><div><p>        return AllSubscriptable(</p></div><div><p>            firstIndexee: { return self.startIndex }, // Error: Cannot convert `() -&gt; Int` to expected `() -&gt; _`</p></div><div><p>            lastIndexee: { return self.endIndex },<br></p></div><div><p>            subscriptee: { return self[$0] },</p></div><div><p>            setSubscriptee: { self[$0] = $1 }</p></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p>        )</p></div><div><p>    }</p></div><div><p>}  </p><p><br></p></div></blockquote>The error, &quot;Cannot convert `() -&gt; Int` to expected `() -&gt; _`&quot;, on the `firstIndexee` closure is very strange since the types are correct and the same as `lastIndexee` which does not have an error. <div><br></div><div>Also if the set subscript in Subscriptable and then all the other set support in AnySubscriptabe and in the extension is removed, then no error.</div><div><br></div><div>Any clues to why?<span class="HOEnZb"><font color="#888888"><br><div><br></div><div>-- Howard.<br></div></font></span></div></div>
<br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>