<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">You mis-labelled you problem in your original email.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><div class="gmail_default"><font face="georgia, serif">    let x = X() as P // this does not compile. Why?</font></div><div class="gmail_default"><font face="georgia, serif">    foo(x)</font></div><div style="font-family:georgia,serif"><br></div><div style="font-family:georgia,serif">The issue is not in line ` let x = X() as P`. It is in line ` foo(x)`, `x&#39;s type is P`, but `foo(:)` request a parameter type of `A`, not `P`.</div><div style="font-family:georgia,serif"><br></div><div style="font-family:georgia,serif"><span style="font-family:arial,sans-serif;font-size:12.800000190734863px">`func foo&lt;A:P&gt;(_ x:A) {}` means, `x` must be `A`, and `A` conforms `P`. But not all `P`s are `A`.</span><br></div><div style="font-family:georgia,serif"><br></div><div style="font-family:georgia,serif">Zhaoxin</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 23, 2016 at 5:26 PM, Adrian Zubarev 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 style="word-wrap:break-word"><div class="m_2092333772827852517bloop_markdown"><p>Whoops, wait a second. Correcting my self here. Copied the wrong url.</p>

<p>Here is the proposal I meant. <a href="https://github.com/apple/swift-evolution/blob/cd9d8b3f1923d16f4381c23d3d335d88d83e32cd/proposals/0126-refactor-metatypes.md" target="_blank">LINK</a></p>

<p></p></div><div class="m_2092333772827852517bloop_original_html"><span class=""><div id="m_2092333772827852517bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div> <br> <div id="m_2092333772827852517bloop_sign_1482485126153929984" class="m_2092333772827852517bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <br></span><span class=""><p class="m_2092333772827852517airmail_on">Am 23. Dezember 2016 um 09:57:49, Adrian Zubarev (<a href="mailto:adrian.zubarev@devandartist.com" target="_blank">adrian.zubarev@devandartist.<wbr>com</a>) schrieb:</p> </span><div><div class="h5"><blockquote type="cite" class="m_2092333772827852517clean_bq"><span><div style="word-wrap:break-word"><div></div><div>








<div class="m_2092333772827852517bloop_markdown">
<ul>
<li>
<p>What are you trying to solve here?</p>
</li>
<li>
<p>Do you heavily rely on what <code>A</code> can be?</p>
</li>
<li>
<p>Can’t you just write <code>func foo(_ x: P) {}</code> (here
<code>P</code> is an <strong>existential</strong> like [in some
future] <code>Any&lt;P&gt;</code>)?!</p>
</li>
<li>
<p><code>AnyObject</code> is for classes, but you’d get the same
result changing <code>X</code> to a class ;)</p>
</li>
</ul>
<p>If you want scratch the surface of what happens to protocols in
a generic context, you could read our proposal about meta types
<a href="https://github.com/apple/swift-evolution/blob/91725ee83fa34c81942a634dcdfa9d2441fbd853/proposals/0126-refactor-metatypes-repurpose-t-dot-self-and-mirror.md" target="_blank">
here</a>.</p>
</div>
<div class="m_2092333772827852517bloop_original_html">

<div id="m_2092333772827852517bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">
<br></div>
<br>
<div id="m_2092333772827852517bloop_sign_1482483025838348032" class="m_2092333772827852517bloop_sign">
<div style="font-family:helvetica,arial;font-size:13px">
-- <br>
Adrian Zubarev<br>
Sent with Airmail</div>
</div>
<br>
<p class="m_2092333772827852517airmail_on">Am 23. Dezember 2016 um 09:43:34, Mikhail
Seriukov via swift-users (<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>)
schrieb:</p>
<blockquote type="cite" class="m_2092333772827852517clean_bq">
<div>
<div>
<div dir="ltr">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="font-size:12.8px"><span>No it does not.</span></div>
<div style="font-size:12.8px"><span>You have made a type out of the
parameter. It’s no longer a protocol.</span></div>
<div style="font-size:12.8px"><span>IMO the failure here is to
understand the difference between a type and a
protocol.</span></div>
<div style="font-size:12.8px"><span>A type (even if empty) is
always a combination of storage with functions (that are assumed to
work on the data in storage)</span></div>
<div style="font-size:12.8px"><span>A protocol is just a definition
of functions without the accompanying data.</span></div>
</blockquote>
<div><span><br>
I see your point. <br>
But actually when I write it as  `<span style="font-size:12.8px">let x = X() as P` I really mean that I want `x`
to be `AnyObject` but conforming to P, not just protocol
itself.<br>
Is it even possible to downcast it this way?</span></span></div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">2016-12-23 14:51 GMT+07:00 Marinus van der
Lugt <span dir="ltr">&lt;<a href="mailto:rien@starbase55.com" target="_blank">rien@starbase55.com</a>&gt;</span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br>
<div>
<blockquote type="cite">
<div><span>On 22 Dec 2016, at 22:43, Howard Lovatt
&lt;<a href="mailto:howard.lovatt@gmail.com" target="_blank">howard.lovatt@gmail.com</a>&gt; wrote:</span></div>
<span><br class="m_2092333772827852517m_3726349150314027147Apple-interchange-newline"></span>
<div>
<div dir="ltr"><span>The following variation works:</span>
<div><span><br></span></div>
<div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(186,45,162)">
<span><span style="font-variant-ligatures:no-common-ligatures">protocol</span>
<span style="font-variant-ligatures:no-common-ligatures">P
{}</span></span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px">
<br></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">
<span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span>
<span style="font-variant-ligatures:no-common-ligatures">P1:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">P</span>
<span style="font-variant-ligatures:no-common-ligatures">{}</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px">
<br></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">
<span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span>
<span style="font-variant-ligatures:no-common-ligatures">X:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">P1</span>
<span style="font-variant-ligatures:no-common-ligatures">{}</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px">
<br></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">
<span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span>
<span style="font-variant-ligatures:no-common-ligatures">foo&lt;A:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">P</span><span style="font-variant-ligatures:no-common-ligatures">&gt;(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span>
<span style="font-variant-ligatures:no-common-ligatures">x:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">A</span><span style="font-variant-ligatures:no-common-ligatures">)
{}</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px">
<br></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">
<span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span>
<span style="font-variant-ligatures:no-common-ligatures">bar()
{</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)">
<span style="font-variant-ligatures:no-common-ligatures"> 
 </span> <span style="font-variant-ligatures:no-common-ligatures">//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)">
<span style="font-variant-ligatures:no-common-ligatures"> 
 </span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span>
<span style="font-variant-ligatures:no-common-ligatures">x =</span>
<span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">X</span><span style="font-variant-ligatures:no-common-ligatures">()</span>
<span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">as</span>
<span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">P1</span>
<span style="font-variant-ligatures:no-common-ligatures">// this
does not compile. Why?</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">
<span style="font-variant-ligatures:no-common-ligatures"> 
 </span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">foo</span><span style="font-variant-ligatures:no-common-ligatures">(x)</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">
<span style="font-variant-ligatures:no-common-ligatures">}</span></div>
</div>
<div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div>
<div><span style="font-variant-ligatures:no-common-ligatures">Which
adds credence to the bug theory.</span></div>
</div>
</div>
</blockquote>
<div><br></div>
<div><br></div>
No it does not.</div>
<div>You have made a type out of the parameter. It’s no longer a
protocol.</div>
<div>IMO the failure here is to understand the difference between a
type and a protocol.</div>
<div>A type (even if empty) is always a combination of storage with
functions (that are assumed to work on the data in storage)</div>
<div>A protocol is just a definition of functions without the
accompanying data.</div>
<div><br></div>
<div>Rien.</div>
<div>
<div class="m_2092333772827852517h5">
<div><br></div>
<div><br></div>
<div><br>
<blockquote type="cite">
<div>
<div dir="ltr">
<div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div>
<div><span style="font-variant-ligatures:no-common-ligatures">Note
two changes: 1. two levels of inheritance and 2. change to classes.
If you do two levels using protocols it doesn&#39;t work if you use
either classes or structs.</span></div>
<div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div>
</div>
<div class="gmail_extra"><br clear="all">
<div>
<div class="m_2092333772827852517m_3726349150314027147gmail_signature" data-smartmail="gmail_signature">  -- Howard.<br></div>
</div>
<br>
<div class="gmail_quote">On 23 December 2016 at 07:29, Kevin
Nattinger <span dir="ltr">&lt;<a href="mailto:swift@nattinger.net" target="_blank">swift@nattinger.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">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>
<div class="m_2092333772827852517m_3726349150314027147h5">
<div><br>
<div>
<blockquote type="cite">
<div>On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-users
&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div>
<br class="m_2092333772827852517m_3726349150314027147m_-7294405302096099227Apple-interchange-newline">

<div>
<div dir="auto">
<div>I suspect a compiler bug since A is a P. The equivalent in
Java works:</div>
<div><br></div>
<div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica">
<span style="font-size:12pt">interface P {}</span></div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica">
<span style="font-size:12pt">class X implements P {}</span></div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px">
<span style="font-size:12pt"> </span><br class="m_2092333772827852517m_3726349150314027147m_-7294405302096099227webkit-block-placeholder">
</div>
<div 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></div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px">
<span style="font-size:12pt"> </span><br class="m_2092333772827852517m_3726349150314027147m_-7294405302096099227webkit-block-placeholder">
</div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica">
<span style="font-size:12pt">void bar() {</span></div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica">
<span style="font-size:12pt">    final P x = new
X();</span></div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica">
<span style="font-size:12pt">    foo(x);</span></div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica">
<span style="font-size:12pt">}</span></div>
<br>
-- Howard. </div>
<div><br>
On 23 Dec 2016, at 3:19 am, Rien via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br>
<br></div>
<blockquote type="cite">
<div><span>IMO the error message says it all:</span><br>
<br>
<span>Playground execution failed: error:
MyPlayground8.playground:9:5: error: cannot invoke &#39;foo&#39; with an
argument list of type &#39;(P)&#39;</span><br>
<span>   foo(x)</span><br>
<span>   ^</span><br>
<br>
<span>MyPlayground8.playground:9:5: note: expected an argument list
of type &#39;(A)&#39;</span><br>
<span>   foo(x)</span><br>
<span>   ^</span><br>
<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>
<br>
<span>Regards,</span><br>
<span>Rien</span><br>
<br>
<span>Site: <a href="http://balancingrock.nl/" target="_blank">http://balancingrock.nl</a></span><br>
<span>Blog: <a href="http://swiftrien.blogspot.com/" target="_blank">http://swiftrien.blogspot.com</a></span><br>
<span>Github: <a href="http://github.com/Swiftrien" target="_blank">http://github.com/Swiftrien</a></span><br>
<span>Project: <a href="http://swiftfire.nl/" target="_blank">http://swiftfire.nl</a></span><br>
<br>
<br>
<br>
<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" target="_blank">swift-users@swift.org</a>&gt;
wrote:</span><br></blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite"><span>Hello community! I&#39; 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"><br></blockquote>
<blockquote type="cite"><span>protocol P
{}</span><br></blockquote>
<blockquote type="cite"><span>struct X:P
{}</span><br></blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite"><span>func foo&lt;A:P&gt;(_ x:A)
{}</span><br></blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite"><span>func bar()
{</span><br></blockquote>
<blockquote type="cite"><span>   //let x = X() //
this compiles</span><br></blockquote>
<blockquote type="cite"><span>   let x = X() as P //
this does not compile. Why?</span><br></blockquote>
<blockquote type="cite">
<span>   foo(x)</span><br></blockquote>
<blockquote type="cite"><span>}</span><br></blockquote>
<blockquote type="cite"><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&#39;m not shure it is.</span><br></blockquote>
<blockquote type="cite"><span>Thanks for the
help.</span><br></blockquote>
<blockquote type="cite">
<span>______________________________<wbr>_________________</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" target="_blank">swift-users@swift.org</a></span><br></blockquote>
<blockquote type="cite"><span><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a></span><br>
</blockquote>
<br>
<span>______________________________<wbr>_________________</span><br>

<span>swift-users mailing list</span><br>
<span><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a></span><br>
<span><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a></span><br>
</div>
</blockquote>
</div>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
</div>
</blockquote>
</div>
<br></div>
</div>
</div>
</div>
</blockquote>
</div>
<br></div>
</div>
</blockquote>
</div>
<br></div>
</div>
</div>
</blockquote>
</div>
<br></div>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div>
</div>
</blockquote>
</div>
<div class="m_2092333772827852517bloop_markdown"></div>


</div></div></span></blockquote></div></div></div><div class="m_2092333772827852517bloop_markdown"><p></p></div></div><br>______________________________<wbr>_________________<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/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>