Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual getter functions don't exist yet when checking inherited interface abstractness. #3841

Closed
norganna opened this issue Apr 6, 2018 · 1 comment

Comments

@norganna
Copy link

norganna commented Apr 6, 2018

As per the discussion at https://ethereum.stackexchange.com/a/44964/34929

It would seem that the issue being discussed may be a problem with the solidity compiler. Perhaps it doesn't recognise that the virtual getters match the signature definintion for the interface functions or they haven't yet been created at the time it's checking for their presence.

The problem can be demonstrated with the following code:

pragma solidity ^0.4.21;

interface ERC20 {
    function balanceOf(address) external view returns (uint);
    function transfer(address, uint) external returns (bool);
}

contract TestA is ERC20 {
    mapping(address=>uint) public balanceOf;

    function TestA() public {
        balanceOf[this] = 1000;
    }

    function transfer(address _to, uint256 _value) external returns (bool success) {
        require(balanceOf[msg.sender] >= _value);
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        require(balanceOf[_to] >= _value);
        return true;
    }
}

contract TestB {
    address a;

    function TestB() public {
        a = new TestA();
    }

    function aBalance() external view returns (uint) {
        return ERC20(a).balanceOf(a);
    }
}

If you try and compile this contract you will end up with an error like:

browser/contract.sol:28:13: TypeError: Trying to create an instance of an abstract contract.
        a = new TestA();
            ^-------^
browser/contract.sol:4:5: Missing implementation:
    function balanceOf(address) external view returns (uint);
    ^-------------------------------------------------------^

However if you remove the is ERC20 then it works fine.

Conversely if you add the getter function manually to TestA:

    function balanceOf(address _to) external view returns (uint value) {
        return balanceOf[_to];
    }

It also works fine.

@norganna norganna changed the title Virtual getter functions don't exist yet when checking interfaces. Virtual getter functions don't exist yet when checking inherited interface abstractness. Apr 6, 2018
@norganna
Copy link
Author

norganna commented Apr 6, 2018

Sounds like a duplicate of #3514 actually.

@norganna norganna closed this as completed Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant