1

From the official doc:

Overloaded functions are also present in the external interface. It is an error if two externally visible functions differ by their Solidity types but not by their external types.

Then followed by an example (I changed B by uint):

pragma solidity >=0.4.16 <0.7.0;

// This will not compile
contract A {
    function f(B _in) public pure returns (B out) {
        out = _in;
    }

    function f(address _in) public pure returns (address out) {
        out = _in;
    }
}

But i actually could compile the above code with no issue. Is this a bug in the doc or something?

$ truffle compile

Compiling your contracts...
===========================
> Compiling ./contracts/Test.sol
> Artifacts written to /.../solidity/study/Test/build/contracts
> Compiled successfully using:
   - solc: 0.6.4+commit.1dca32f3.Emscripten.clang
3

You seem to have missed the explanation at the bottom of that example:

Both f function overloads above end up accepting the address type for the ABI although they are considered different inside Solidity.

Translation to English:

While B and address are considered by the compiler as different types, for the ABI they are identical (B is essentially equivalent to address).

Once you change B to uint, that coding example will obviously compile because uint and address are treated as different types also in the ABI.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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