Document function overloading#3218
Conversation
docs/contracts.rst
Outdated
| Functions | ||
| ********* | ||
|
|
||
| .. index:: ! _view-functions |
There was a problem hiding this comment.
I think with this the view-functions link is gone? (It is referenced by the ABI documentation.)
There was a problem hiding this comment.
Yes, sorry will reinstate.
docs/contracts.rst
Outdated
| pragma solidity ^0.4.0; | ||
|
|
||
| contract A { | ||
| function Z(uint _in) public pure returns (uint out) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?"
There was a problem hiding this comment.
I mention that in the "Function Resolution" sub section further down.
https://github.com/ethereum/solidity/pull/3218/files#diff-754689a291c0a19b500c31eb6c1d30c7R649
docs/contracts.rst
Outdated
|
|
||
| :: | ||
|
|
||
| pragma solidity ^0.4.0; |
There was a problem hiding this comment.
This needs a later version due to the use of pure. I think it is 0.4.16.
docs/contracts.rst
Outdated
| out = _in; | ||
| } | ||
|
|
||
| function z(address _in) public pure returns (address out) |
There was a problem hiding this comment.
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.
eac944b to
7c8f4b1
Compare
docs/contracts.rst
Outdated
| ``Z`` function in the scope of contract ``A``. | ||
|
|
||
| :: | ||
| // This will not compile |
There was a problem hiding this comment.
This example should be compiling fine?
docs/contracts.rst
Outdated
| ==================== | ||
| 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``. |
There was a problem hiding this comment.
Still refers to function name in capital.
| ************** | ||
|
|
||
| ============== | ||
| Functions can be declared ``view`` in which case they promise not to modify the state. |
There was a problem hiding this comment.
Please don't remove here and below the extra new line after a heading.
7c8f4b1 to
09895e5
Compare
09895e5 to
875338f
Compare
|
@axic I am struggling to understand why the travis build fails. Something to do with compiling |
|
@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. |
|
@elenadimitrova please rebase and remove the Also if possible rename the function Otherwise it looks great! |
875338f to
c6a4aba
Compare
|
Thanks @axic . Changes pushed. |
Adds a dedicated section for functions and moves the documentation for
view,pureand fallback functions under that. In addition it adds a section for "Function overloading".Closes #2176