5

Is there a way in Solidity to call super class external functions?

Normally with inherited contracts, when overriding inherited functions you can also call the original function logic with super.functionName().

With external functions, the only way to call them within the contract that defines them is with this.functionName().

Now what if I wanted to override an inherited external function and call the super class function, how would I achieve this if possible?

contract Foo {

    // I want to call this from the contract that inherits it
    function do() external virtual public {
         // nothing
    }
}

contract Bar is Foo {
    function do() external public override(Foo) {
        super.do() // TypeError: Member "do" not found or not visible after argument-dependent lookup in contract super Bar.

        this.do() // revert

        this.super.do() // Want to do something like this
    }
}
3
  • 1
    I'm not entirely sure, so I'm going to drop this as a comment first, but does adding the virtual parameter to the original function help (so it would be function do() external virtual public)? If it does, I can write it up as a proper answer. Commented Nov 18, 2020 at 9:47
  • 1
    potentially useful source: docs.soliditylang.org/en/v0.7.4/… Commented Nov 18, 2020 at 9:47
  • 2
    Sorry my example was incomplete. I've edited to add the virtual.
    – Shiri
    Commented Nov 18, 2020 at 15:09

1 Answer 1

4

Turns out this is not possible.

Inheriting functions and attempting to call the parent class version is deemed as an internal call. Since an override would replace the entry point for the overridden function and the logic of the function (which still exists in the contract) cannot be accessed due to the use of external, overriding an external function and attempting to also use it's parent logic is impossible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.