<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I suspect a compiler bug since A is a P. The equivalent in Java works:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">interface P {}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">class X implements P {}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 13.8px;"><span style="font-size: 12pt;">&nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">&lt;A extends P&gt; void foo(A x) {}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 13.8px;"><span style="font-size: 12pt;">&nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">void bar() {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">&nbsp; &nbsp; final P x = new X();</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">&nbsp; &nbsp; foo(x);</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">}</span></p><br>-- Howard.&nbsp;</div><div><br>On 23 Dec 2016, at 3:19 am, Rien via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><span>IMO the error message says it all:</span><br><span></span><br><span>Playground execution failed: error: MyPlayground8.playground:9:5: error: cannot invoke 'foo' with an argument list of type '(P)'</span><br><span> &nbsp;&nbsp;&nbsp;foo(x)</span><br><span> &nbsp;&nbsp;&nbsp;^</span><br><span></span><br><span>MyPlayground8.playground:9:5: note: expected an argument list of type '(A)'</span><br><span> &nbsp;&nbsp;&nbsp;foo(x)</span><br><span> &nbsp;&nbsp;&nbsp;^</span><br><span></span><br><span>I.e. you are passing in a protocol while the function is specified for a type.</span><br><span>Said other way: On which data do you expect the protocol to operate?</span><br><span></span><br><span>Regards,</span><br><span>Rien</span><br><span></span><br><span>Site: <a href="http://balancingrock.nl">http://balancingrock.nl</a></span><br><span>Blog: <a href="http://swiftrien.blogspot.com">http://swiftrien.blogspot.com</a></span><br><span>Github: <a href="http://github.com/Swiftrien">http://github.com/Swiftrien</a></span><br><span>Project: <a href="http://swiftfire.nl">http://swiftfire.nl</a></span><br><span></span><br><span></span><br><span></span><br><span></span><br><blockquote type="cite"><span>On 22 Dec 2016, at 17:05, Mikhail Seriukov via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Hello community! I' wondering if somebody can explain this to me.</span><br></blockquote><blockquote type="cite"><span>Please take look at the snippet.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>protocol P {}</span><br></blockquote><blockquote type="cite"><span>struct X:P {}</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>func foo&lt;A:P&gt;(_ x:A) {}</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>func bar() {</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;//let x = X() // this compiles</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;let x = X() as P // this does not compile. Why?</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;foo(x)</span><br></blockquote><blockquote type="cite"><span>}</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>I expect the both cases to work though. But only first works? And I do not understand why.</span><br></blockquote><blockquote type="cite"><span>My coworkers said that it is a compiler bug, but I'm not shure it is.</span><br></blockquote><blockquote type="cite"><span>Thanks for the help.</span><br></blockquote><blockquote type="cite"><span>_______________________________________________</span><br></blockquote><blockquote type="cite"><span>swift-users mailing list</span><br></blockquote><blockquote type="cite"><span><a href="mailto:swift-users@swift.org">swift-users@swift.org</a></span><br></blockquote><blockquote type="cite"><span><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></blockquote><span></span><br><span>_______________________________________________</span><br><span>swift-users mailing list</span><br><span><a href="mailto:swift-users@swift.org">swift-users@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></div></blockquote></body></html>