Skip to content

Document function overloading#3218

Merged
chriseth merged 1 commit intoargotorg:developfrom
elenadimitrova:documentation/2176-overload-resolution
Dec 12, 2017
Merged

Document function overloading#3218
chriseth merged 1 commit intoargotorg:developfrom
elenadimitrova:documentation/2176-overload-resolution

Conversation

@elenadimitrova
Copy link
Contributor

Adds a dedicated section for functions and moves the documentation for view, pure and fallback functions under that. In addition it adds a section for "Function overloading".

Closes #2176

Functions
*********

.. index:: ! _view-functions
Copy link
Contributor

@axic axic Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with this the view-functions link is gone? (It is referenced by the ABI documentation.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry will reinstate.

pragma solidity ^0.4.0;

contract A {
function Z(uint _in) public pure returns (uint out)
Copy link
Contributor

@axic axic Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the indentation from the other examples (well, from the style guide if possible) and use a lower case function name.

Convention was so far to use contract C { function f(); function g(); ... }. Though contract A, contract B, etc. makes sense if inheritance is used in the examples.


Function Overloading
====================
A Contract can have multiple functions of the same name but with different arguments.
Copy link
Contributor

@axic axic Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also mention that return parameters are not taken into considering for overloading.

Simple reasoning for this: "Which version of an overloaded function to use if it is used in a statement without assigning its return values?"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mention that in the "Function Resolution" sub section further down.
https://github.com/ethereum/solidity/pull/3218/files#diff-754689a291c0a19b500c31eb6c1d30c7R649


::

pragma solidity ^0.4.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a later version due to the use of pure. I think it is 0.4.16.

out = _in;
}

function z(address _in) public pure returns (address out)
Copy link
Contributor

@axic axic Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctly detected by the compiler:

/tmp/tmp.If4S5vMgWU/test_9299c7c399da4cec7ae3fe218d6b8fbe4474ab118851fcf2eeeb49c8ecf50eb5.sol:8:9: Error: Function overload clash during conversion to external types for arguments.
        function z(address _in) public pure returns (address out)
        ^

This example will need the comment right above the pragma: // This will not compile

That disables the example for tests.

@elenadimitrova elenadimitrova force-pushed the documentation/2176-overload-resolution branch 3 times, most recently from eac944b to 7c8f4b1 Compare November 23, 2017 07:29
``Z`` function in the scope of contract ``A``.

::
// This will not compile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example should be compiling fine?

====================
A Contract can have multiple functions of the same name but with different arguments.
This also applies to inherited functions. The following example shows overloading of the
``Z`` function in the scope of contract ``A``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still refers to function name in capital.

**************

==============
Functions can be declared ``view`` in which case they promise not to modify the state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove here and below the extra new line after a heading.

@elenadimitrova elenadimitrova force-pushed the documentation/2176-overload-resolution branch from 7c8f4b1 to 09895e5 Compare November 23, 2017 13:42
@elenadimitrova elenadimitrova force-pushed the documentation/2176-overload-resolution branch from 09895e5 to 875338f Compare November 28, 2017 13:56
@elenadimitrova
Copy link
Contributor Author

@axic I am struggling to understand why the travis build fails. Something to do with compiling zeppelin-solidity?

@chriseth
Copy link
Contributor

chriseth commented Dec 4, 2017

@elenadimitrova yes, the failures are unrelated to your changes. We always compile the latest version of the zeppelin libraries as a test, and they added a feature that disallows any warning, but we always have the prerelease warning from the compiler.

@axic
Copy link
Contributor

axic commented Dec 12, 2017

@elenadimitrova please rebase and remove the .pyc file (it has been added to .gitignore).

Also if possible rename the function z to f as that's our common style.

Otherwise it looks great!

@elenadimitrova elenadimitrova force-pushed the documentation/2176-overload-resolution branch from 875338f to c6a4aba Compare December 12, 2017 08:27
@elenadimitrova
Copy link
Contributor Author

Thanks @axic . Changes pushed.

@chriseth chriseth merged commit a0e67de into argotorg:develop Dec 12, 2017
@elenadimitrova elenadimitrova deleted the documentation/2176-overload-resolution branch December 23, 2017 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants