<html><head><style>
body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        padding:1em;
        margin:auto;
        background:#fefefe;
}
h1, h2, h3, h4, h5, h6 {
        font-weight: bold;
}
h1 {
        color: #000000;
        font-size: 28pt;
}
h2 {
        border-bottom: 1px solid #CCCCCC;
        color: #000000;
        font-size: 24px;
}
h3 {
        font-size: 18px;
}
h4 {
        font-size: 16px;
}
h5 {
        font-size: 14px;
}
h6 {
        color: #777777;
        background-color: inherit;
        font-size: 14px;
}
hr {
        height: 0.2em;
        border: 0;
        color: #CCCCCC;
        background-color: #CCCCCC;
display: inherit;
}
p, blockquote, ul, ol, dl, li, table, pre {
        margin: 15px 0;
}
a, a:visited {
        color: #4183C4;
        background-color: inherit;
        text-decoration: none;
}
#message {
        border-radius: 6px;
        border: 1px solid #ccc;
        display:block;
        width:100%;
        height:60px;
        margin:6px 0px;
}
button, #ws {
        font-size: 12 pt;
        padding: 4px 6px;
        border-radius: 5px;
        border: 1px solid #bbb;
        background-color: #eee;
}
code, pre, #ws, #message {
        font-family: Monaco;
        font-size: 10pt;
        border-radius: 3px;
        background-color: #F8F8F8;
        color: inherit;
}
code {
        border: 1px solid #EAEAEA;
        margin: 0 2px;
        padding: 0 5px;
}
pre {
        border: 1px solid #CCCCCC;
        overflow: auto;
        padding: 4px 8px;
}
pre > code {
        border: 0;
        margin: 0;
        padding: 0;
}
#ws { background-color: #f8f8f8; }
.bloop_markdown table {
border-collapse: collapse;
font-family: Helvetica, arial, freesans, clean, sans-serif;
color: rgb(51, 51, 51);
font-size: 15px; line-height: 25px;
padding: 0; }
.bloop_markdown table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
.bloop_markdown table tr:nth-child(2n) {
background-color: #f8f8f8; }
.bloop_markdown table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
.bloop_markdown table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
.bloop_markdown table tr th :first-child, table tr td :first-child {
margin-top: 0; }
.bloop_markdown table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }
.bloop_markdown blockquote{
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777; }
blockquote > :first-child {
margin-top: 0; }
blockquote > :last-child {
margin-bottom: 0; }
code, pre, #ws, #message {
word-break: normal;
word-wrap: normal;
}
hr {
display: inherit;
}
.bloop_markdown :first-child {
-webkit-margin-before: 0;
}
code, pre, #ws, #message {
font-family: Menlo, Consolas, Liberation Mono, Courier, monospace;
}
.send { color:#77bb77; }
.server { color:#7799bb; }
.error { color:#AA0000; }</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="bloop_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">LINK</a></p>
<p></p></div><div class="bloop_original_html"><style>body{font-family:Helvetica,Arial;font-size:13px}</style><div id="bloop_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="bloop_sign_1482485126153929984" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 23. Dezember 2016 um 09:57:49, Adrian Zubarev (<a href="mailto:adrian.zubarev@devandartist.com">adrian.zubarev@devandartist.com</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div><div>
<title></title>
<div class="bloop_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<P></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">
here</a>.</p>
</div>
<div class="bloop_original_html">
<div id="bloop_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="bloop_sign_1482483025838348032" class="bloop_sign">
<div style="font-family:helvetica,arial;font-size:13px">
-- <br>
Adrian Zubarev<br>
Sent with Airmail</div>
</div>
<br>
<p class="airmail_on">Am 23. Dezember 2016 um 09:43:34, Mikhail
Seriukov via swift-users (<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>)
schrieb:</p>
<blockquote type="cite" class="clean_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"><<a href="mailto:rien@starbase55.com" target="_blank">rien@starbase55.com</a>></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 class="">On 22 Dec 2016, at 22:43, Howard Lovatt
<<a href="mailto:howard.lovatt@gmail.com" target="_blank">howard.lovatt@gmail.com</a>> wrote:</span></div>
<span class=""><br class="m_3726349150314027147Apple-interchange-newline"></span>
<div>
<div dir="ltr"><span class="">The following variation works:</span>
<div><span class=""><br></span></div>
<div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(186,45,162)">
<span class=""><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<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">>(</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="h5">
<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'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_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"><<a href="mailto:swift@nattinger.net" target="_blank">swift@nattinger.net</a>></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_3726349150314027147h5">
<div><br>
<div>
<blockquote type="cite">
<div>On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-users
<<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div>
<br class="m_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_3726349150314027147m_-7294405302096099227webkit-block-placeholder">
</div>
<div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica">
<span style="font-size:12pt"><A extends P> 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_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 <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> 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 'foo' with an
argument list of type '(P)'</span><br>
<span> foo(x)</span><br>
<span> ^</span><br>
<br>
<span>MyPlayground8.playground:9:5: note: expected an argument list
of type '(A)'</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 <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>>
wrote:</span><br></blockquote>
<blockquote type="cite"><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"><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<A:P>(_ 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'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>
_______________________________________________<br>
swift-users mailing list<br>
swift-users@swift.org<br>
https://lists.swift.org/mailman/listinfo/swift-users<br></div>
</div>
</blockquote>
</div>
<div class="bloop_markdown"></div>
</div></div></span></blockquote></div><div class="bloop_markdown"><p></p></div></body></html>