Annotation/Keyword To Automatically Call Super in Override Methods

I am not against it - in fact I do think it would be better! The only reason I suggested @requiresSuper was to keep things consistent.

2 Likes

Oh, that's me, but I had mentioned the @requiresSuper only to say why I didn't like it. Sorry if that post wasn't clear.

1 Like

How about an alternative approach to solving the postulated problem:

class A {
    let a1: Int
    let a2: Int

    @override(by: { $0 + $1 })
    func sum() -> Int {
        return a1 + a2
    }
}

class B: A {
    let b1: Int
    let b2: Int

    override func sum() -> Int {
        return b1 + b2
    }
}

This would translate to:

class A {
    let a1: Int
    let a2: Int

    func sum() -> Int {
        return self._sum_partial()
    }

    private func _sum_partial() -> Int {
        return a1 + a2
    }

    final var _sum_reduce: (Int, Int) -> Int {
        return { $0 + $1 }
    }
}

class B: A {
    let b1: Int
    let b2: Int

    override func sum() -> Int {
        return _sum_reduce(super.sum(), _sum_patial())
    }    

    private func _sum_partial() -> Int {
        return b1 + b2
    }
}