<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 22, 2016, at 4:43 PM, Howard Lovatt via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">The following variation works:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> P {}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> P1:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">P</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> X:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">P1</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> foo&lt;A:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">P</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> x:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">A</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> bar() {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures" class="">//let x = X() // this compiles</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> x = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">X</span><span style="font-variant-ligatures: no-common-ligatures;" class="">() </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">as</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">P1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures" class="">// this does not compile. Why?</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(x)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Which adds credence to the bug theory.</span></div></div></div></blockquote><div><br class=""></div>It’s an intentional limitation. Protocols do not conform to themselves. Lifting the restriction would be difficult to do efficiently given our representation of generics and protocols at runtime.</div><div><br class=""></div><div>Slava</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Note two changes: 1. two levels of inheritance and 2. change to classes. If you do two levels using protocols it doesn't work if you use either classes or structs.</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature">&nbsp; -- Howard.<br class=""></div></div>
<br class=""><div class="gmail_quote">On 23 December 2016 at 07:29, Kevin Nattinger <span dir="ltr" class="">&lt;<a href="mailto:swift@nattinger.net" target="_blank" class="">swift@nattinger.net</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">I recall seeing a request on the -evolution list for something like `T := X` to indicate it could be X itself or anything inheriting / implementing it, so it’s certainly known behavior, if not desired. IMO it’s a bug and `:` should be fixed to include the root type, whether or not that requires a discussion on -evolution.<div class=""><div class="h5"><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="m_-7294405302096099227Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class="">I suspect a compiler bug since A is a P. The equivalent in Java works:</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class=""><span style="font-size:12pt" class="">interface P {}</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class=""><span style="font-size:12pt" class="">class X implements P {}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 13.8px;" class=""><span style="font-size:12pt" class="">&nbsp;</span><br class="m_-7294405302096099227webkit-block-placeholder"></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class=""><span style="font-size:12pt" class="">&lt;A extends P&gt; void foo(A x) {}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 13.8px;" class=""><span style="font-size:12pt" class="">&nbsp;</span><br class="m_-7294405302096099227webkit-block-placeholder"></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class=""><span style="font-size:12pt" class="">void bar() {</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class=""><span style="font-size:12pt" class="">&nbsp; &nbsp; final P x = new X();</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class=""><span style="font-size:12pt" class="">&nbsp; &nbsp; foo(x);</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class=""><span style="font-size:12pt" class="">}</span></div><br class="">-- Howard.&nbsp;</div><div class=""><br class="">On 23 Dec 2016, at 3:19 am, Rien via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><span class="">IMO the error message says it all:</span><br class=""><span class=""></span><br class=""><span class="">Playground execution failed: error: MyPlayground8.playground:9:5: error: cannot invoke 'foo' with an argument list of type '(P)'</span><br class=""><span class=""> &nbsp;&nbsp;&nbsp;foo(x)</span><br class=""><span class=""> &nbsp;&nbsp;&nbsp;^</span><br class=""><span class=""></span><br class=""><span class="">MyPlayground8.playground:9:5: note: expected an argument list of type '(A)'</span><br class=""><span class=""> &nbsp;&nbsp;&nbsp;foo(x)</span><br class=""><span class=""> &nbsp;&nbsp;&nbsp;^</span><br class=""><span class=""></span><br class=""><span class="">I.e. you are passing in a protocol while the function is specified for a type.</span><br class=""><span class="">Said other way: On which data do you expect the protocol to operate?</span><br class=""><span class=""></span><br class=""><span class="">Regards,</span><br class=""><span class="">Rien</span><br class=""><span class=""></span><br class=""><span class="">Site: <a href="http://balancingrock.nl/" target="_blank" class="">http://balancingrock.nl</a></span><br class=""><span class="">Blog: <a href="http://swiftrien.blogspot.com/" target="_blank" class="">http://swiftrien.blogspot.com</a></span><br class=""><span class="">Github: <a href="http://github.com/Swiftrien" target="_blank" class="">http://github.com/Swiftrien</a></span><br class=""><span class="">Project: <a href="http://swiftfire.nl/" target="_blank" class="">http://swiftfire.nl</a></span><br class=""><span class=""></span><br class=""><span class=""></span><br class=""><span class=""></span><br class=""><span class=""></span><br class=""><blockquote type="cite" class=""><span class="">On 22 Dec 2016, at 17:05, Mikhail Seriukov via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt; wrote:</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""></span><br class=""></blockquote><blockquote type="cite" class=""><span class="">Hello community! I' wondering if somebody can explain this to me.</span><br class=""></blockquote><blockquote type="cite" class=""><span class="">Please take look at the snippet.</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""></span><br class=""></blockquote><blockquote type="cite" class=""><span class="">protocol P {}</span><br class=""></blockquote><blockquote type="cite" class=""><span class="">struct X:P {}</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""></span><br class=""></blockquote><blockquote type="cite" class=""><span class="">func foo&lt;A:P&gt;(_ x:A) {}</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""></span><br class=""></blockquote><blockquote type="cite" class=""><span class="">func bar() {</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""> &nbsp;&nbsp;&nbsp;//let x = X() // this compiles</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""> &nbsp;&nbsp;&nbsp;let x = X() as P // this does not compile. Why?</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""> &nbsp;&nbsp;&nbsp;foo(x)</span><br class=""></blockquote><blockquote type="cite" class=""><span class="">}</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""></span><br class=""></blockquote><blockquote type="cite" class=""><span class="">I expect the both cases to work though. But only first works? And I do not understand why.</span><br class=""></blockquote><blockquote type="cite" class=""><span class="">My coworkers said that it is a compiler bug, but I'm not shure it is.</span><br class=""></blockquote><blockquote type="cite" class=""><span class="">Thanks for the help.</span><br class=""></blockquote><blockquote type="cite" class=""><span class="">______________________________<wbr class="">_________________</span><br class=""></blockquote><blockquote type="cite" class=""><span class="">swift-users mailing list</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a></span><br class=""></blockquote><blockquote type="cite" class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a></span><br class=""></blockquote><span class=""></span><br class=""><span class="">______________________________<wbr class="">_________________</span><br class=""><span class="">swift-users mailing list</span><br class=""><span class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a></span><br class=""></div></blockquote></div>______________________________<wbr class="">_________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></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=""></body></html>