<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 7, 2016, at 8:12 AM, Mark Anders via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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"> </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"> </span><span class="">Containable :</span><span class="Apple-converted-space"> </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"> </span><span class="">Refers {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space"> </span><span class="">to :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Node</span><span class="Apple-converted-space"> </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"> </span><span class="">Link :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Refers</span><span class="Apple-converted-space"> </span><span class="">{</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space"> </span><span class="">to :</span><span class="Apple-converted-space"> </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=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">init</span><span class="">(n :</span><span class="Apple-converted-space"> </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=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">to</span><span class="Apple-converted-space"> </span><span class="">= n</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=""><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"> </span><span class="">Contains :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Refers</span><span class="Apple-converted-space"> </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=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space"> </span><span style="" class="">to :</span><span class="Apple-converted-space"> </span><span class="">Containable</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">init</span><span class="">(c :</span><span class="Apple-converted-space"> </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=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">to</span><span class="Apple-converted-space"> </span><span class="">= c</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> }</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></div></blockquote><div><br class=""></div>You can use an associated type for this instead,</div><div><br class=""></div><div>protocol Refers {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>associatedtype NodeType</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>var to: NodeType { get }</div><div>}</div><div><br class=""></div><div>I agree that your example should work -- the rules for patching method overrides and protocol witnesses are more stringent than they need to be. There's an interesting engineering challenge in generalizing the logic and also cleaning it up to share as much code as possible with the subtype matching code in the constraint solver.</div><div><br class=""></div><div>Slava</div><div><br class=""></div><div><blockquote type="cite" class=""><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 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. </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), </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? Or could protocols be enhanced to to allow matching</div><div class="">derived types, similar to assignment and func parameter rules? </div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><span style="font-family: helvetica, arial;" class="">Mark</span></div></div></div><span 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; float: none; display: inline !important;" class="">_______________________________________________</span><br 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=""><span 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; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br 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=""><a href="mailto:swift-evolution@swift.org" 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="">swift-evolution@swift.org</a><br 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>