<div dir="ltr">On Sat, Jan 7, 2017 at 11:34 AM, Xiaodi Wu <span dir="ltr">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">`Self` _always_ refers to the dynamic type of `self`. It just happens to be that in the case of structs the dynamic type is the same as the static type. The idea of having a shorthand for the containing type (spelled #Self or StaticSelf) was discussed during consideration of SE-0068. The accepted version of the proposal rejects that idea, having adopted the position that &quot;You will continue to specify full type names for any other use. Joe Groff writes, &#39;I don&#39;t think it&#39;s all that onerous to have to write ClassName.foo if that&#39;s really what you specifically mean.&#39;&quot;</div></blockquote><div><br></div><div>I should add, I say this because even though we have revisited proposals after their acceptance on discovery of an unforeseen problem, IMO it&#39;s highly disagreeable to try to reconsider an accepted proposal before it&#39;s even been implemented on the basis of disagreeing with the conclusion of a discussion that was already considered previously.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Sat, Jan 7, 2017 at 11:14 AM, thislooksfun via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">I like this idea, however, if I understand the proposal correctly, I think that the naming would make more sense the other way around. `Self` is, at least in my head, tied directly and statically to the enclosing type, where as `Current` sounds more dynamic, and could change from place-to-place.<br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><br>-thislooksfun (tlf)</div>

</div>
<br><div><blockquote type="cite"><div><div class="m_3646779703029911180gmail-h5"><div>On Jan 7, 2017, at 4:38 AM, Adrian Zubarev via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_3646779703029911180gmail-m_6743338456365996728Apple-interchange-newline"></div></div><div><div><div class="m_3646779703029911180gmail-h5"><div class="m_3646779703029911180gmail-m_6743338456365996728bloop_markdown" style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><p style="margin:15px 0px">Hi Swift community,</p><p style="margin:15px 0px">I’d like to talk to about current<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>keyword. If I’m not totally mistaken then the current<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>has a few meanings:</p><ol style="margin:15px 0px"><li style="margin:15px 0px">Refer to the<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><em>current</em><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>type, or refer to the dynamic type for non-final classes inside containing type (SE–0068 - not yet implemented).</li><li style="margin:15px 0px">For non-final class types use<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>as return type on the conforming super type (or<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><em>return an instance of receiver<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code></em>).</li></ol><p style="margin:15px 0px">Let me visualize the behaviors quickly in some short code snippet:</p><pre style="margin:15px 0px;font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal"><code class="m_3646779703029911180gmail-m_6743338456365996728swift" style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:0px;margin:0px;padding:0px;word-break:normal;word-wrap:normal">protocol Foo {
    func foo(_ f: Self) -&gt; Self
}

class A : Foo {
    // forced to use `A` as parameter type and `Self` as return type
    func foo(_ f: A) -&gt; Self { return self }
    // Returning `A()` would cause an error: Cannot convert return expression of type &#39;A&#39; to return type &#39;Self&#39;
    func bar() -&gt; A { return A() /* or self */ }
    func zoo() -&gt; Self { return /* only */ self }
}

class B : A {
    // Both is fine `B` or `Self` as the return type
    // If `B` is used you can return a different instance like `B()`
    // `Self` does only allow `self` to be used here
    override func foo(_ f: A) -&gt; B { return self }
}

struct D : Foo {
    // No `Self` allowed here at all
    func foo(_ f: D) -&gt; D { return self /* or D() */ }
}
</code></pre><p style="margin:15px 0px">The behavior of<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>is a little magical, because it sometimes refers to the<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><em>current</em><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>type it is used in, or it has a contract of using<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">self</code>.</p><hr style="height:0.2em;border:0px;color:rgb(204,204,204);background-color:rgb(204,204,204);display:inherit"><p style="margin:15px 0px">I propose of introducing a new keyword called<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Current</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>to solve a few problems here.</p><ol style="margin:15px 0px"><li style="margin:15px 0px"><p style="margin:15px 0px"><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>on parameter types would be disallowed for protocol members, because conformances to that protocol already disallow that (see<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">A</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>above). Instead one would use<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Current</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>and get the correct meaning.</p><pre style="margin:15px 0px;font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal"><code class="m_3646779703029911180gmail-m_6743338456365996728swift" style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:0px;margin:0px;padding:0px;word-break:normal;word-wrap:normal">protocol Boo {
    func boo(_ b: Current) -&gt; Self
}
     
procotol Loo {
    func loo() -&gt; Current
}
     
class X : Boo, Loo {
    func boo(_ b: X) -&gt; Self { return self }
    func loo() -&gt; X { return self /* or X() */ }
}
     
final class Y : Boo {
    func boo(_ b: X) -&gt; Y { return self /* or Y */ }
}
</code></pre></li><li style="margin:15px 0px"><p style="margin:15px 0px">Using<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>inside the containing type would always mean as one would refer to the dynamic type, like the magical syntax function<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">type(of:)</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>does.</p></li><li style="margin:15px 0px"><p style="margin:15px 0px"><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Current</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>can only refer to the current containing type.</p></li><li style="margin:15px 0px"><p style="margin:15px 0px">On classes<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>has always the contract of returning<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">self</code>.</p></li><li style="margin:15px 0px"><p style="margin:15px 0px"><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Self</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>could be discouraged in favor of<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Current</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>on value types, as a shorthand to refer to the containing type.</p></li><li style="margin:15px 0px"><p style="margin:15px 0px">Generics could benefit from<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span><code style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal">Current</code><span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span>too:</p><pre style="margin:15px 0px;font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(204,204,204);overflow:auto;padding:4px 8px;word-break:normal;word-wrap:normal"><code class="m_3646779703029911180gmail-m_6743338456365996728swift" style="font-family:menlo,consolas,&#39;liberation mono&#39;,courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:0px;margin:0px;padding:0px;word-break:normal;word-wrap:normal">extension AReallyLongNonFinalClassName {
    func casted&lt;T : Current&gt;() -&gt; T { ... }
}
// `Self` wouldn&#39;t here, because it would refer to the dynamic type
</code></pre></li></ol><p style="margin:15px 0px">#1 Would affect a lot of protocols which implies that it would affect ABI.</p><hr style="height:0.2em;border:0px;color:rgb(204,204,204);background-color:rgb(204,204,204);display:inherit"><p style="margin:15px 0px">These are the first ideas I had in my mind. We can polish it further if it receives positive and constructive feedback.</p><p style="margin:15px 0px">Best regards,<span class="m_3646779703029911180gmail-m_6743338456365996728Apple-converted-space"> </span></p><div style="margin:15px 0px"><br class="m_3646779703029911180gmail-m_6743338456365996728webkit-block-placeholder"></div></div><div class="m_3646779703029911180gmail-m_6743338456365996728bloop_original_html" style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><div id="m_3646779703029911180gmail-m_6743338456365996728bloop_customfont" style="font-family:helvetica,arial;font-size:13px;margin:0px"><br></div><br><div id="m_3646779703029911180gmail-m_6743338456365996728bloop_sign_1483779578617182976" class="m_3646779703029911180gmail-m_6743338456365996728bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div></div><div class="m_3646779703029911180gmail-m_6743338456365996728bloop_markdown" style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><div style="margin:15px 0px"><br class="m_3646779703029911180gmail-m_6743338456365996728webkit-block-placeholder"></div></div></div></div><span style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254);float:none;display:inline">______________________________<wbr>_________________</span><br style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><span style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254);float:none;display:inline">swift-evolution mailing list</span><br style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><a href="mailto:swift-evolution@swift.org" style="color:rgb(65,131,196);background-color:rgb(254,254,254);text-decoration:none;font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color:rgb(65,131,196);background-color:rgb(254,254,254);text-decoration:none;font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br style="font-family:helvetica,arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254)"></div></blockquote></div><br></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>