Syntax for calling super implementation when overriding a method

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Syntax for calling super implementation when overriding a method

Duncan Mak
Hello Per,

I see that there's syntax (this) for referring to the current instance.

When I'm defining a class hierarchy, and I'd like to override a method in a
subclass, is there a similar syntax, i.e. (super)?

For now, I'm doing this (superclass:method instance ...), but it'd be nice
not having to explicitly name the superclass.


Thanks!

--
Duncan.
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for calling super implementation when overriding a method

Per Bothner
On 4/1/19 11:58 AM, Duncan Mak wrote:
> Hello Per,
>
> I see that there's syntax (this) for referring to the current instance.
>
> When I'm defining a class hierarchy, and I'd like to override a method in a
> subclass, is there a similar syntax, i.e. (super)?
>
> For now, I'm doing this (superclass:method instance ...), but it'd be nice
> not having to explicitly name the superclass.

The Kawa manual suggests using invoke-special, and has a few examples:

    (invoke-special supersuper (this) 'methodname arg ...)

where 'methodname is '*init* in the case of a constructor.

However (as you and the manual also notes), this is annoyingly verbose.

One approach is as you suggest:

    ((super):methodname arg ...)

This would start by having (super) expand to a distinct variant of ThisExpr,
but changing the code-generation to call invokespecial.

An alternative (possibly easier to implement) might be

   (invoke-super 'methodname arg ...)

Either of these would be a good project in terms of learning more about how Kawa works.

--
        --Per Bothner
[hidden email]   http://per.bothner.com/