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

Automatic getters not recognised in interface implementations #4847

Closed
adamdossa opened this issue Aug 22, 2018 · 5 comments
Closed

Automatic getters not recognised in interface implementations #4847

adamdossa opened this issue Aug 22, 2018 · 5 comments

Comments

@adamdossa
Copy link

adamdossa commented Aug 22, 2018

Description

In code like the below, address public balance has an automatic getter function (as can be seen in the corresponding ABI).

However we need to redefine it to avoid the compiler complaining that Test does not fully implement ITest.

Any idea if this is a bug or a feature (and if so why)?

    pragma solidity ^0.4.24;
    
    interface ITest {
        function balance() external returns (address);
    }
    
    contract Test is ITest {
        address public balance;
        
        // Why is this function needed?
        function balance() public returns (address) {
            return balance;
        }
    }
@adamdossa
Copy link
Author

This has another odd side-effect in code like the below, where it isn't possible to specify in an interface that there is a function decimals as your damned if you include it, and damned if you don't ;-).

pragma solidity ^0.4.24;

interface HasDecimals {
    function decimals() external view returns (uint8);
}

contract DetailedERC20 {
  string public name;
  string public symbol;
  uint8 public decimals;

  constructor(string _name, string _symbol, uint8 _decimals) public {
    name = _name;
    symbol = _symbol;
    decimals = _decimals;
  }
}

contract Test is HasDecimals, DetailedERC20 {
    
    constructor (string _name, string _symbol, uint8 _decimals) public
        DetailedERC20(_name, _symbol, _decimals)
    {}
    
    //Uncommenting the below function gives a compile error:
    //DeclarationError: Identifier already declared
    //Commenting the below function gives a compile error:
    //Missing implementation: function decimals() external view returns (uint8);
    function decimals() external view returns (uint8) {
        return decimals;
    }

}

@leonardoalt
Copy link
Member

That's a good point. Actually, with the latest version you'll get an already declared error also for the first example.
Before I go ahead and call it a bug, we'll have to discuss what the expected behavior is; that is, whether the public state variable should implicitly implement the interface function or if those things should be separated on the language level.
I personally tend to the opinion that the variable accessor should implicitly implement the interface function.

@adamdossa
Copy link
Author

Yep - I think since automatic getters are part of the language specification (and reflected in ABIs) they should be considered a match for the interface (which is effectively an ABI as it maps 1-1 with ABIs).

There are other oddities like my second comment above where it seems like if you're inheriting from a contract, the inheritance is done at the ABI level (so you can't redefine an existing function encoded as a public state variable) but if the public state variable is in the same contract, you're free to redefine its getter function.

@axic
Copy link
Member

axic commented Aug 27, 2018

This may be a duplicate of #3514.

@chriseth
Copy link
Contributor

chriseth commented Sep 4, 2018

Closing as duplicate although I though we already fixed that. sigh

@chriseth chriseth closed this as completed Sep 4, 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

4 participants