Looks like a compiler bug to me. <br><br>On Tuesday, 8 March 2016, Mark Anders via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div></div><div>








<div style="margin:0px">Consider the following (you can paste it in a Playground to see the error):</div>
<div style="margin:0px"><br></div>
<div>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span style="color:#bb2ca2">class</span>
<span>Node {
}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span style="color:#bb2ca2">class</span>
<span>Containable :</span>
<span style="color:#4f8187">Node</span><span>{}</span></p>
<p>
<br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span style="color:#bb2ca2">protocol</span>
<span>Refers
{</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
 </span> <span style="color:#bb2ca2">var</span>
<span>to
:</span> <span style="color:#4f8187">Node</span>
<span>{</span><span style="color:#bb2ca2">get</span><span>}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span>}</span></p>
<p>
<br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span style="color:#bb2ca2">class</span>
<span>Link
:</span> <span style="color:#4f8187">Refers</span>
<span>{</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
 </span> <span style="color:#bb2ca2">var</span>
<span>to
:</span> <span style="color:#4f8187">Node</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
 </span> <span style="color:#bb2ca2">init</span><span>(n
:</span> <span style="color:#4f8187">Node</span><span>)
{</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
     </span> <span style="color:#4f8187">to</span>
<span>=
n</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
  }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span>}</span></p>
<p>
<br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span style="color:#bb2ca2">class</span>
<span>Contains
:</span> <span style="color:#4f8187">Refers</span>
<span>{</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)">
<span style="color:#000000"> 
 </span> <span style="color:#bb2ca2">var</span>
<span style="color:#000000">to
:</span> <span>Containable</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
 </span> <span style="color:#bb2ca2">init</span><span>(c
:</span> <span style="color:#4f8187">Containable</span><span>)
{</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
     </span> <span style="color:#4f8187">to</span>
<span>=
c</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span> 
  }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">
<span>}</span></p>
</div>
<div><span><br></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><br><div>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.  </div><div>This would allow me to treat the structure in a type safe way (i.e. only a Containable can have a Contains relationship), </div><div>while me to have a set of Refers and iterate through each Node.</div><div><br>
<div>Is there a reason why the type must match exactly?  Or
could protocols be enhanced to to allow matching</div>
<div>derived types, similar to assignment and func parameter rules?  </div><div><br></div><div><br></div><div><span style="font-family:helvetica,arial">Mark</span></div>
</div>


</div></div>
</blockquote><br><br>-- <br>-- Howard.<br>