Describe the bug
Overloaded function resolution can trigger a failure depending on order of function declarations. I have a minimal reproducible version of this bug here. To reproduce, run cargo run -- testcase/overloaded_order_matters/*.sol.
For instance, the following code works fine for solc and solang's parse_and_resolve:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Overloaded {
// Version 1
function f(uint n) internal pure returns (uint) {
return n;
}
// Version 2
function f(uint n, uint x) internal pure returns (uint) {
return n + x;
}
// Version 3
function f(int n, uint x) internal pure returns (int) {
uint result = f(uint256(n), x);
return n > 0 ? int(result) : -int(result);
}
}
However, parse_and_resolve fails to handle this case, where the final two functions are reversed:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Overloaded {
// Version 1
function f(uint n) internal pure returns (uint) {
return n;
}
// Version 3
function f(int n, uint x) internal pure returns (int) {
uint result = f(uint256(n), x);
return n > 0 ? int(result) : -int(result);
}
// Version 2
function f(uint n, uint x) internal pure returns (uint) {
return n + x;
}
}
I tried all 6 possible orders of function declarations and this is the only one that fails 🤔. I also wasn't able to make this trigger with only two functions, so I think this is a minimal test case?
Describe the bug Overloaded function resolution can trigger a failure depending on order of function declarations. I have a minimal reproducible version of this bug here. To reproduce, run
cargo run -- testcase/overloaded_order_matters/*.sol
.For instance, the following code works fine for solc and solang's parse_and_resolve:
However, parse_and_resolve fails to handle this case, where the final two functions are reversed:
Running solang here causes the following error:
I tried all 6 possible orders of function declarations and this is the only one that fails 🤔. I also wasn't able to make this trigger with only two functions, so I think this is a minimal test case?