0
contract A {
    uint256 x;
    function myFunc(uint256 _x) public {
        x = _x;
    }
}

contract B is A {
    function myFunc1(uint256 _x) public {
        x = _x;
    }

}

contract Test {
    constructor() {
        A.myFunc.selector; // works
        B.myFunc1.selector; // works
        B.myFunc.selector; // doesn't work
    }
}

If I have a contract B that inherits from contract A I would expect that I would be able to get a function selector for an inherited function, just as I would be able to call B(_addr).myFunc() on the inherited contract. But instead I get this error on compilation:

TypeError: Member "myFunc" not found or not visible after argument-dependent lookup in type(contract B).
  --> contracts/A.sol:23:9:
   |
23 |         B.myFunc.selector; // doesn't work
   |         ^^^^^^

Does anyone have an idea why this is the case?

1
  • Just figured out passing an address to B works, so B(_addr).myFunc.selector but the question above still stands Nov 8, 2022 at 22:58

1 Answer 1

0

This works in Remix:

pragma solidity 0.8.17;

contract A {
    uint256 x;
    function myFunc(uint256 _x) public {
        x = _x;
    }
}

contract B is A {
    function myFunc1(uint256 _x) public {
        x = _x;
    }

}

// Defining calling contract
contract Test {
    constructor() {
        // Creating child contract object
        B b = new B(); 
        A.myFunc.selector; // works
        B.myFunc1.selector; // works
        b.myFunc.selector; // works
    }
}

The issue is that you need to create the child contract object in the calling contract before you can call the myFunc function originally defined in the parent contract.

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.