[swift-evolution] Proposal: Add @requires_super attribute

Vester Gottfried vester.gottfried at gmail.com
Wed Dec 16 10:32:37 CST 2015

Some class based libraries/frameworks expect the consumer to subclass
certain classes and override specific method and require that the super
implementation of an overridden method is being called.

Not calling the super implementation is a common source of bugs that may be
prevented if the compiler checks if super is called, like it does in some
cases of init().


class Box {
    func addStuff() { ... }

Overriding class Box's addStuff without calling super.addStuff() should
result in an error

class Chest : Box {
    override addStuff() {
         // ERROR: addStuff() requires call to super.addStuff()

Objective-C developers know this as NS_REQUIRES_SUPER and I think its worth
thinking about adapting it.

I hope my proposal was clear and thanks for reading,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151216/7d9e7b3b/attachment.html>

More information about the swift-evolution mailing list