[swift-evolution] Language syntax proposal - shorthand for super invocations

Petroules Jake Jake.Petroules at theqtcompany.com
Mon Feb 8 23:31:47 CST 2016


Hello,

I have a language syntax proposal. I've read the Swift evolution guidelines and hopefully this is the proper way to start. So, my proposal is:

Permit a shorthand syntax for invoking the supertype implementation of a property or function. A single statement 'super' is equivalent to invoking the supertype implementation, forwarding the arguments unchanged, and returning the result. For example, the following samples:

override func mouseEntered(theEvent: NSEvent) {
    super
    handleMouseEvent(theEvent)
}

override func specialValue(key: String) -> Int {
    return super + 1
}

override var widgetCount: Int {
    return super + 5
}

are exactly equivalent to the following samples:

override func mouseEntered(theEvent: NSEvent) {
    super.mouseEntered(theEvent)
    handleMouseEvent(theEvent)
}

override func specialValue(key: String) -> Int {
    return super.specialValue(key) + 1
}

override var widgetCount: Int {
    return super.widgetCount + 5
}

Alternatives/complementary ideas:

- Require `super()` or `super(...)` syntax for invocations which are function calls, for consistency with other function calls in the language and/or to indicate that arguments are forwarded

Looking forward to your feedback.

Thanks!
--
Jake Petroules - jake.petroules at theqtcompany.com<mailto:jake.petroules at theqtcompany.com>
Consulting Services Engineer - The Qt Company

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


More information about the swift-evolution mailing list