-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Overload resolution for .value()-modified functions #526
Comments
A reduced example for clarity. Working:
Failing:
Working with
The problem appears with |
Yes, we have a pending story for that. Sorry for the inconvenience. It is a bit hard to fix because you can only do overload resolution when you know the arguments but you need to know the type of the function so that you can tell whether it has a |
Not fully aware of the internals of the compiler, but would an explicit flag (i.e. #500 and its appropriate keywords on functions) help? Which cases |
@chriseth with |
Not really, the thing is that the argumentTypes AST annotation has to be pulled through several AST nodes, and this will not even solve cases like |
This affects me in 0.5.1.
contract ChannelFactory {
function newChannel(address payable _recipient, uint256 _duration) external payable returns(PaymentChannel _channel){
_channel = (new PaymentChannelETH).value(msg.value)(_recipient, _duration);
}
function newChannel(Token _token, address _recipient, uint256 _duration) external returns(PaymentChannel _channel) {
_channel = new PaymentChannelERC20(_token, _recipient, _duration);
_token.transferFrom(msg.sender, address(_channel), _token.allowance(msg.sender, address(this)));
}
}
contract Account {
function openChannel(ChannelFactory _factory, Token _token, address payable _recipient, uint256 _duration, uint256 _amount) external {
_token.approve(address(_factory), _amount);
_factory.newChannel(_token, _recipient, _duration);
}
function openChannel(ChannelFactory _factory, address payable _recipient, uint256 _duration, uint256 _amount) external {
_factory.newChannel.value(_amount)(_recipient, _duration);
}
} See example failing to compile built in remix.ethereum.org: https://gist.github.com/3esmit/fce237c187d1f54eacb2c434553b2dd2 While this is not fixed, compilation should fail when one function being overloaded have |
As this also affects I see that is a hard problem to solve.
I think the best way would be rework how one contract call/send to other, and using the interface call to generate the abi that would be used in the call/send. I imagine: |
Is there currently no way around this issue? So basically there's no way to call an overloaded payable function with some value? |
You can use address(otherContract).call.value(amount)(abi.encodeWithSignature("method(uint256,bytes)", param1, param2)); |
Or you perform a type conversion to a contract that only has one of the two overloads. |
...and has to switch to lower level calls w/ a sprinkling of assembly to get at the return values in order to deal with overloaded interfaces. Pertinent issue here: ethereum/solidity#526 (comment)
...and has to switch to lower level calls w/ a sprinkling of assembly to get at the return values in order to deal with overloaded interfaces. Pertinent issue here: ethereum/solidity#526 (comment)
Could the syntax be changed? IMO .value()() seems out of place in Solidity anyway since functions aren't first-class objects. |
If you have a good idea about how to change the syntax, we are all ears! Note that functions actually are first-class objects in Solidity: https://solidity.readthedocs.io/en/v0.5.8/types.html#function-types |
...and has to switch to lower level calls w/ a sprinkling of assembly to get at the return values in order to deal with overloaded interfaces. Pertinent issue here: ethereum/solidity#526 (comment)
...and has to switch to lower level calls w/ a sprinkling of assembly to get at the return values in order to deal with overloaded interfaces. Pertinent issue here: ethereum/solidity#526 (comment)
...and has to switch to lower level calls w/ a sprinkling of assembly to get at the return values in order to deal with overloaded interfaces. Pertinent issue here: ethereum/solidity#526 (comment)
This issue can be re-visited now that #8177 is almost merged |
It will be almost the same problem. But we should add a test, actually! |
I have a method, which gets called with value transfer using the
<method>.value(<value>)(<args>)
semantic. This fails when overloading.Works:
Fails when adding
.value()
inusingShapeshift
:The text was updated successfully, but these errors were encountered: