Skip to content
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

Can't overload function by changing only return types #259

Closed
nmushegian opened this issue Nov 29, 2015 · 3 comments
Closed

Can't overload function by changing only return types #259

nmushegian opened this issue Nov 29, 2015 · 3 comments

Comments

@nmushegian
Copy link

function stuff() returns (uint) {}

function stuff() returns (uint, bool) {}

These have distinct signatures, but the compiler won't let me create both versions

@chriseth
Copy link
Contributor

This is on purpose. For overload resolution, only the parameter types are taken into account, as is customary in many other languages. The reason is that you can easily omit the return values (or their types), but not the parameters. In both of the following examples, resolution is ambiguous.

stuff();
var x = stuff();

The main problem, though, is that resolution does not need to terminate after one step and can create ambiguities even if you use the return values:

function stuff() returns (uint) {}
function stuff() returns (bool) {}
function g(uint) returns (bool) {}
function g(bool) returns (bool) {}
function h() {
bool x = g(stuff());
}

@nmushegian
Copy link
Author

Darn. I feel like this is an extension that will inevitably be required, to fit a contract into two different systems that expect different APIs.

I'm sure you could annotate a function in a way that will force expressions to never have an ambiguous type but it sounds like solidity 2.0 feature

@axic
Copy link
Member

axic commented Apr 27, 2016

These have distinct signatures, but the compiler won't let me create both versions

@nmushegian they are not part of the signature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants