<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Slava/Joe, thanks for clarifying the issue and Slava for providing more depth on what needs to happen. Like David, I was unsure if this was just a bug or an enhancement.</div><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><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Out of curiosity, you mention some related issues, and I just ran into something similar and wonder if it’s related too.</div><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><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">class</span><span style="font-variant-ligatures: no-common-ligatures"> A {}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">class</span><span style="font-variant-ligatures: no-common-ligatures"> B : </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures"> {}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;"><span style="font-variant-ligatures: no-common-ligatures"></span><br></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">var</span><span style="font-variant-ligatures: no-common-ligatures"> arrayOfA = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures">]()</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">let</span><span style="font-variant-ligatures: no-common-ligatures"> arrayOfB : [</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">] = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">()]</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">arrayOfA</span><span style="font-variant-ligatures: no-common-ligatures">.appendContentsOf(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">arrayOfB</span><span style="font-variant-ligatures: no-common-ligatures">)</span></p><div><span style="font-variant-ligatures: no-common-ligatures"><br></span></div></div></blockquote> This fails to compile, though doing arrayOfA.append(B()) works as I would expect.<div><br></div><div>Is it related? &nbsp;In general, it seems that Swift’s type system is stricter than I would expect.</div><div><br></div><div>Do these types of issues seem in-scope for Swift 3?<br><div><br> <div id="bloop_sign_1457471044165755136" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">Mark</div></div> <br><p class="airmail_on">On March 8, 2016 at 1:22:13 AM, Slava Pestov via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div></div><div>



<title></title>


I would suggest a formal proposal because its a bit involved I
think. It should ideally match the subtyping rules, so
<div class=""><br class=""></div>
<div class="">- A matches B if A is a subclass of B</div>
<div class="">- A matches P if A conforms to P</div>
<div class="">- A matches A?</div>
<div class="">- A! matches A? and vice versa</div>
<div class="">- T1 -&gt; U1 matches T2 -&gt; U2 if T2 is a subtype
of T1 and U1 is a subtype of U2</div>
<div class="">- some rules for ‘throws’ functions</div>
<div class=""><br class=""></div>
<div class="">I think there might be some tricky cases with
associated type inference. We should be careful not to break any
existing code.</div>
<div class=""><br class=""></div>
<div class="">Also a related proposal would be to allow enum cases
to witness static method requirements, and methods to witness
property requirements of function type and vice versa, but these
seem less useful.</div>
<div class=""><br class=""></div>
<div class="">Code for matching witnesses is in
TypeCheckProtocol.cpp, and override matching is elsewhere (I think
Decl.cpp in lib/AST/)? Take a look if you’re curious about what the
rules are today.</div>
<div class=""><br class=""></div>
<div class="">Slava</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Mar 7, 2016, at 11:06 PM, David Hart via
swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">

<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">If it’s an obvious omission, is it better to have it as a
bug than a formal proposal?
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On 08 Mar 2016, at 00:16, Joe Groff via
swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">

<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On Mar 7, 2016, at 8:12 AM, Mark Anders via
swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div>
<div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<div id="bloop_customfont" style="margin: 0px;" class="">Consider
the following (you can paste it in a Playground to see the
error):</div>
<div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div>
<div class="">
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space">&nbsp;</span><span class="">Node {
}</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space">&nbsp;</span><span class="">Containable
:</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Node</span><span class="">{}</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">protocol</span><span class="Apple-converted-space">&nbsp;</span><span class="">Refers
{</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space">&nbsp;</span><span class="">to
:</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Node</span><span class="Apple-converted-space">&nbsp;</span><span class="">{</span><span style="color: rgb(187, 44, 162);" class="">get</span><span class="">}</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space">&nbsp;</span><span class="">Link
:</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Refers</span><span class="Apple-converted-space">&nbsp;</span><span class="">{</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space">&nbsp;</span><span class="">to
:</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Node</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">init</span><span class="">(n
:</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Node</span><span class="">)
{</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp; &nbsp;
&nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">to</span><span class="Apple-converted-space">&nbsp;</span><span class="">=
n</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space">&nbsp;</span><span class="">Contains
:</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Refers</span><span class="Apple-converted-space">&nbsp;</span><span class="">{</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="" class="">&nbsp; &nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space">&nbsp;</span><span style="" class="">to
:</span><span class="Apple-converted-space">&nbsp;</span><span class="">Containable</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">init</span><span class="">(c
:</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">Containable</span><span class="">) {</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp; &nbsp;
&nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(79, 129, 135);" class="">to</span><span class="Apple-converted-space">&nbsp;</span><span class="">=
c</span></div>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp; }</span></div>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""></p>
<div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div>
</div>
<div class=""><span class=""><br class=""></span></div>
This currently does not work because it seems that to adopt a
protocol, the type of protocol var must match exactly.</div>
<div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">
<div class="">It would be great if objects could be said to adopt a
protocol if the type of the var is the type or a derived type.
&nbsp;</div>
<div class="">This would allow me to treat the structure in a type
safe way (i.e. only a Containable can have a Contains
relationship),&nbsp;</div>
<div class="">while me to have a set of Refers and iterate through
each Node.</div>
<div class=""><br class="">
<div class="">Is there a reason why the type must match
exactly?&nbsp; Or could protocols be enhanced to to allow
matching</div>
<div class="">derived types, similar to assignment and func
parameter rules? &nbsp;</div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class=""></div>
No fundamental reason, this just isn't something we've had time to
implement. It should be straightforward to support.</div>
<div class=""><br class=""></div>
<div class="">-Joe</div>
</div>
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div>
</blockquote>
</div>
<br class=""></div>
</div>
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div>
</blockquote>
</div>
<br class=""></div>


_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div></div></span></blockquote></div></div></body></html>