<div dir="ltr">On Sat, Jan 7, 2017 at 4:00 PM, Braeden Profile 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><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 style="word-wrap:break-word"><span class=""><pre style="white-space:pre-wrap;background-color:rgb(255,255,255)"><blockquote type="cite"><i>
</i><i> One could workaround the problem and use final, but what if the class
</i><i> meant to be subtypeable? Self simply does not work in this scenario.
</i><i>
</i>
It works exactly as it should in this scenario. If A isn&#39;t final, then by
definition it&#39;s impossible for A to make a copy of type Self. I see,
however, what you mean, which is that you wish you could write a protocol
requirement for a function that returns #Self.
</blockquote></pre></span><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(146,146,146)"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">What do you mean?  Even with the limited `Self` support in Swift 3, I can write a very effective copying paradigm.</div></span></div></div></div></blockquote><div><br></div><div>That was poor writing on my part. What I meant was that, exactly as you show below, `Building.copy()` needs to invoke a method on a subclass to obtain an instance of type `Self`. There is nothing that `Building` can do without relying on its subclasses in order to obtain such an instance (I can&#39;t imagine a use case _why_ one couldn&#39;t do that, but I understood Adrian as saying that he has that problem).</div><div><br></div><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><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(146,146,146)"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"></div></span></div></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#008f01"><pre style="color:rgb(0,0,0);font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:0.94em;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);border:1px solid rgb(204,204,204);white-space:pre-wrap;word-wrap:break-word;padding:5px"><div style="font-family:Helvetica;font-size:12px;white-space:normal"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">protocol</span><span style="font-variant-ligatures:no-common-ligatures"> Copyable</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">func</span><span style="font-variant-ligatures:no-common-ligatures"> copy() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(170,46,184)">Self</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Building: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Copyable</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">var</span><span style="font-variant-ligatures:no-common-ligatures"> floors = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(218,32,0)">1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,1)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">required</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">init</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span>{  }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">func</span><span style="font-variant-ligatures:no-common-ligatures"> copy() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(170,46,184)">Self</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> dynamicType = type(of: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> newObject = dynamicType.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">init</span><span style="font-variant-ligatures:no-common-ligatures">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span>newObject.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">floors</span><span style="font-variant-ligatures:no-common-ligatures"> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">floors</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">return</span><span style="font-variant-ligatures:no-common-ligatures"> newObject</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>}</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Mansion: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Building</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">var</span><span style="font-variant-ligatures:no-common-ligatures"> butlers = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(218,32,0)">3</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">override</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">func</span><span style="font-variant-ligatures:no-common-ligatures"> copy() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(170,46,184)">Self</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(146,146,146)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">//<span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>let newObject = super.copy()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> newObject = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">super</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">copy</span><span style="font-variant-ligatures:no-common-ligatures">() </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">as</span><span style="font-variant-ligatures:no-common-ligatures">! </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Mansion</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span>newObject.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">butlers</span><span style="font-variant-ligatures:no-common-ligatures"> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">butle<wbr>rs</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(146,146,146)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">//<span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>return newObject</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">unsafeBitCast</span><span style="font-variant-ligatures:no-common-ligatures">(<wbr>newObject, to: type(of: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>}</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> hoboHouse = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Building</span><span style="font-variant-ligatures:no-common-ligatures">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures">hoboHouse</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures">floors</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(218,32,0)">0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> beggarHouse = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">hoboHouse</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">copy</span><span style="font-variant-ligatures:no-common-ligatures">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">print</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">beggarHouse</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures">floors</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(146,146,146)">// &quot;0&quot;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> myHouse = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Mansion</span><span style="font-variant-ligatures:no-common-ligatures">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures">myHouse</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures">floors</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(218,32,0)">4</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> yourHouse = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">myHouse</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">copy</span><span style="font-variant-ligatures:no-common-ligatures">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">print</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">yourHouse</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures">floors</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(146,146,146)">// “4”</span></div><div><span style="font-variant-ligatures:no-common-ligatures;color:rgb(146,146,146)"><br></span></div></div></pre><div><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Besides the poor support for `Self` in the function body (SE–0068 fixes that), it seems like an acceptable way of doing it.</span></div></span></div></div></div></blockquote><div><br></div><div>Agree, it&#39;s a shame that one needs to jump through that hoop with `unsafeBitCast`. With SE-0068, I&#39;d hope that `super.copy() as! Self` would be sufficient.</div><div><br></div><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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:#929292"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Of course, I would love being able to use an initializer setup, but there are serious bugs in the implementation.</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:0.94em;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);border:1px solid rgb(204,204,204);white-space:pre-wrap;word-wrap:break-word;padding:5px"><div style="white-space:normal;font-family:Helvetica;font-size:12px"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,1)"><span style="font-variant-ligatures:no-common-ligatures">protocol</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> Clonable</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">init</span><span style="font-variant-ligatures:no-common-ligatures">(other: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(73,134,114)">Self</span><span style="font-variant-ligatures:no-common-ligatures">)</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,1)"><span style="font-variant-ligatures:no-common-ligatures">extension</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Clonable</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">func</span><span style="font-variant-ligatures:no-common-ligatures"> clone() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(73,134,114)">Self</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span>{ </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">return</span><span style="font-variant-ligatures:no-common-ligatures"> type(of: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">).</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">init</span><span style="font-variant-ligatures:no-common-ligatures">(<wbr>other: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">) }</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(95,174,174)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">class</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> Base: </span><span style="font-variant-ligatures:no-common-ligatures">Clonable</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">var</span><span style="font-variant-ligatures:no-common-ligatures"> x: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(91,38,153)">Int</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">init</span><span style="font-variant-ligatures:no-common-ligatures">(x: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(91,38,153)">Int</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span>{ </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">x</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;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,1)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">required</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">init</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(other: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Base</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span>{ </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">x</span><span style="font-variant-ligatures:no-common-ligatures"> = other.</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></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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Derived: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Base</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(91,38,153)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">var</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> y: </span><span style="font-variant-ligatures:no-common-ligatures">String</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">init</span><span style="font-variant-ligatures:no-common-ligatures">(x: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(91,38,153)">Int</span><span style="font-variant-ligatures:no-common-ligatures">, y: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(91,38,153)">String</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">y</span><span style="font-variant-ligatures:no-common-ligatures"> = y</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">super</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">init</span><span style="font-variant-ligatures:no-common-ligatures">(x: 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 class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(146,146,146)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">// Should be required by the Clonable protocol, but it isn&#39;t.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,1)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">required</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">init</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(other: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Derived</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">y</span><span style="font-variant-ligatures:no-common-ligatures"> = other.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">y</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">super</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">init</span><span style="font-variant-ligatures:no-common-ligatures">(other: other)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><br class="m_-602078394375739685webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(146,146,146)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">// Required because it was `required` in Base.  Even a `Derived` calls this initializer to clone, which is wrong.  Bugs abound.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,1)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures">required</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">init</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(other: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Base</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(2,37,188)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_-602078394375739685Apple-tab-span" style="white-space:pre-wrap">                </span>{ </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">fatalError</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">&quot;init(other:) is wrong.&quot;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">) }</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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><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(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures"> me = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(95,174,174)">Derived</span><span style="font-variant-ligatures:no-common-ligatures">(x: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(218,32,0)">1</span><span style="font-variant-ligatures:no-common-ligatures">, y: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(2,37,188)">&quot;food&quot;</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(146,146,146)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,1)">let</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> alienClone = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">me</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)">clone</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">() </span><span style="font-variant-ligatures:no-common-ligatures">// &quot;init(other:) is wrong.&quot;</span></div><div><br></div></div></pre></div></span></div></div></blockquote><div><br></div><div>Agree. That seems wrong. Great example.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>