Calling an overridden function in an overriding function

Suppose a function is defined for an abstract type (say AbstractMyType), and it is overridden for a concrete subtype (say MyType<:AbstractMyType). The overriding function does extra work on top of the work implemented in the overridden function, so I would like to call the overridden function inside the overriding function. Is this possible?

The following code describes what I would like to achieve:

abstract type AbstractMyType end

function myfun(x::AbstractMyType)  # function to be overridden below
   ...
end

struct MyType<:AbstractMyType
   ...
end

function myfun(x::MyType)  # override above function
    myfun(x::AbstractMytype)  # this line is something I want to achieve

    # Do more work
    ...
end

You are probably looking for invoke.

3 Likes