On Tuesday, 25 February 2014 at 00:18:47 UTC, Namespace wrote:
Maybe:
----
extend void foo() { ... }
----
would force you to use super.foo() and otherwise gives an error?

----
class Foo {
    void foo() {
        // ...
    }
}

class Bar : Foo {
    extend void foo() {
// compiler will force you (opposed to override) that you call super.foo() but it isn't important where. You can call it at the end or at the start or wherever you wish.

    }
}
----

Maybe we could also reduce the super.FUNCTION with "super" as for base class constructors. Or to distinguish we could name it "base":

----
class Foo {
    void foo() {
        // ...
    }
}

class Bar : Foo {
    extend void foo() {
        base(); /// will be rewritten to super.foo();
    }
}
----

The latter is of course for the "lazy" people. :)

This is not good enough, this makes the "extend" optional on overridden functions. What it needs to be is a way to ensure that if your function is overridden by a base class that it is guaranteed to be called by the new function.

Something like this

class A
{
     extendable void foo(){}
}

class B : A
{
override void foo(){}// compilation error, super.foo not called
}

This makes it non-optional. You have to call super.foo if you want to override foo.

Also, in some cases it is not enough just to ensure that it is called, some times you will want to make sure that it is called at the beginning or end of the function. Though this is harder to get right, not really sure how it would work with returns.

Also I think it would make sense for something like this to be transitive. For instance in the above example, the new foo should also be extendable or else the guarantee breaks.

Reply via email to