-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Validating the arguments of an overloaded function fails due to having a different number of parameters than the base function #569
Comments
Ran into this issue while testing an implementation of ERC223 which overloads |
I fixed this in our truffle fork here
I can provide PR to |
As an option, we could call overloaded methods via web3 directly, i've created an article with details https://beresnev.pro/test-overloaded-solidity-functions-via-truffle/ |
No, that's not how the function "overloading" works in Solidity; it's not that the last-defined function with that name is the "real" one, but rather all functions with the same name are valid, if they have different input parameters. From the example in the original post, if a contract has the functions:
The ABI would include something like:
It would be valid to call either function, since the signature for the two is different ( In this case, the Truffle testing infrastructure needs to know how to parse out: instance.theFn.call('first param', 'second param'); // call theFn(string,string)
instance.theFn.call('first param'); // call theFn(string)
instance.theFn.call('first param', { from: accounts[3] }); // call theFn(string), using account[3]
instance.theFn.call('first param', 'second param', { from: accounts[3] }); // call theFn(string,string), using account[3] Done this way, it would need to do some introspection on the last argument given, to see if it's an options object or some other type of input. Looks like pull requests 75 and 94 do account for this need with two separate (but compatible options), so looks like they are correct, even though this original issue's requested resolution is not the way Solidity handles the situation. |
How would I call a function overload with the same number of parameters, but different types (string and uint)? |
Truffle doesn't work with overloaded functions. See: trufflesuite/truffle#569 trufflesuite/truffle#737
Closing this, as Truffle v4 basically had no support for overloaded functions. This is now resolved in Truffle v5. Please see the v5 release notes about overloaded functions. Thanks! |
Issue
As the title says, attempting to call an overloaded function from e.g. a JS test fails, since the validation for the number of function parameters fails, not taking into account that there might be 2 functions with the same name.
Steps to Reproduce
In a contract:
In a test:
instance.theFn.call('first param', 'second param')
will fail, since the validator in
cli.bundled.js
(see full stacktrace below) doesn't take into account that there could be multiple functions with the same name, but different number of parameters.It's important to call the function that is defined last, that's the one ignored by the validator (calling the first version of the function, with only 1 param, works fine).
Expected Behavior
I would expect to be able to call an overloaded function from js tests, since it's valid Solidity.
Actual Results
Environment
The text was updated successfully, but these errors were encountered: