<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body 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><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=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" 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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>