<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=""><div class=""><div class="">I have also been considering something like this for stage 2, but since we are discussing it now this is what I think would be most feasible:</div><div class=""><br class=""></div><div class="">1) Unless you know exactly what a subclass should do, you can not make assumptions about when a subclass should call its super implementation. This is truer the more general the class is. Take the method setFrame on NSView as an example; We might want to save some state before calling super, we might want to tweak the input parameters before sending them on to super, and we properly want to perform some custom view logic after calling super. NSView have no way of knowing when you should invoke super in a subclass.</div><div class=""><br class=""></div><div class="">2) I think it would be desirable if the default behavior is that a subclass is expected to call super in methods it overrides, not doing so should be a compile warning. This will be the general case, and I think it should be the default behavior.</div><div class=""><br class=""></div><div class="">3) I think you should be able to silence that warning somehow. I am thinking something like:</div><div class="">override! func setFrame(...) { // note the ! at the end of override</div><div class=""> // not calling super</div><div class="">}</div><div class=""><br class=""></div><div class="">4) There should be a macro / swift keyword that specifies that there is no need to call super. Something like @discardableFunc would be close to the existing @discardableResult annotation in Swift 3. This should be added to all functions where the default implementation is empty or unimportant etc.</div><div class=""><br class=""></div><div class="">5) There should be a macro / swift keyword that specifies that the subclass is not allowed to call the super implementation. @deposedFunc? A native English speaker can properly come up with a better name. There are a few cases where this is relevant; NSOperations start() function is not allowed to call super. Using this keyword should make it a warning to call super and again I imagine that should also be silenced by using override! in case you are forced to call super anyway for some reason.</div><div class=""><br class=""></div><div class="">Please let me know what you think, but I think a formal proposal should wait to stage 2.</div></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 25 Nov 2016, at 17.36, Kevin Nattinger 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=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">I agree. An NS_REQUIRES_SUPER equivalent was on my list of things to propose during stage 2, and I don't see a reason to enforce order. <br class=""><br class=""></div><div class=""><br class="">On Nov 25, 2016, at 04:42, Tino Heth via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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="">What are your thoughts on this?</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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="">Just to throw out a strawman:</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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="">// Warn if override doesn’t begin with “super.foo()”</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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="">__attribute(swift_requires_super_call_at_begin) </div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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=""><br class=""></div><div class=""> // Warn if override doesn’t end with “super.foo()”</div><div class="">__attribute(swift_requires_super_call_at_end)</div></div></div></blockquote></div><br class=""><div class="">I myself would already be happy if Swift had an equivalent to NS_REQUIRES_SUPER (preferably with a different name ;-).</div><div class="">The ability to indicate that super shouldn't be called when overriding would be nice as well — both situations happen in Cocoa, and it isn't enforced, but only documented.</div><div class=""><br class=""></div><div class="">I don't have any examples where the position of the call to super matters, and my personal opinion is that this feature wouldn't pay off:</div><div class="">Of course, there are situations where order is important — but as with willSet/didSet, it might only be important for the overriding class, not for super.</div><div class=""><br class=""></div><div class="">- Tino</div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></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=""></body></html>