ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
22.66k stars 5.62k forks source link

Member not unique after argument-dependent lookup, really ? #15144

Open Amxx opened 1 month ago

Amxx commented 1 month ago

Description

Lets consider the following code

pragma solidity ^0.8.0;

library MyLibrary {
    function identity(bytes1 self) internal pure returns (bytes1) { return self; }
    function identity(bytes2 self) internal pure returns (bytes2) { return self; }
    function identity(bytes3 self) internal pure returns (bytes3) { return self; }
}

contract MyContract {
    using MyLibrary for *;
    function fn1(bytes1 value) external pure returns (bytes1) { return value.identity(); }
    function fn3(bytes2 value) external pure returns (bytes2) { return value.identity(); }
    function fn3(bytes3 value) external pure returns (bytes3) { return value.identity(); }
}

When trying to compile that, I'm getting errors for fn1 and fn2. My understanding is that the compiler believes that there exist multiple versions of identity that match bytes1 and bytes2. That may be because some bytesXx are implicitely convertible to bigger ones?

Only having a single version of identity forces the result to be a bytes3 ...

A fix availble today if to redefine all values types I'm using as UDVT, but that is making all the code more complex.

Environment

Steps to Reproduce

See above.