<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="">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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 22, 2016, at 2:17 PM, Howard Lovatt 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 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><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 13.8px;" class=""><span style="font-size: 12pt;" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;" class=""><span style="font-size: 12pt;" class=""><A extends P> void foo(A x) {}</span></div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 13.8px;" class=""><span style="font-size: 12pt;" class=""> </span><br class="webkit-block-placeholder"></p><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=""> 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=""> 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. </div><div class=""><br class="">On 23 Dec 2016, at 3:19 am, Rien via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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=""> foo(x)</span><br class=""><span class=""> ^</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=""> foo(x)</span><br class=""><span class=""> ^</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/" class="">http://balancingrock.nl</a></span><br class=""><span class="">Blog: <a href="http://swiftrien.blogspot.com/" class="">http://swiftrien.blogspot.com</a></span><br class=""><span class="">Github: <a href="http://github.com/Swiftrien" class="">http://github.com/Swiftrien</a></span><br class=""><span class="">Project: <a href="http://swiftfire.nl/" 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 <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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<A:P>(_ 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=""> //let x = X() // this compiles</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""> let x = X() as P // this does not compile. Why?</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""> 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="">_______________________________________________</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" 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" class="">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br class=""></blockquote><span class=""></span><br class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-users mailing list</span><br class=""><span class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br class=""></div></blockquote></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>