diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-07-03 21:20:59 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-07-10 17:38:33 +0800 |
commit | 65631cffc2127fc603371c67f85d2c07da07c3ca (patch) | |
tree | a6f0de8c9b0d494d1801de22735fd9f3b3a8061f | |
parent | 46d6454b1f47e53c791d71aba26bb953ec667433 (diff) | |
download | dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar.gz dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar.zst dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.zip |
Update documentation and Changelog.
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | docs/frequently-asked-questions.rst | 47 |
2 files changed, 6 insertions, 42 deletions
diff --git a/Changelog.md b/Changelog.md index 304f70ea..db05fc17 100644 --- a/Changelog.md +++ b/Changelog.md @@ -33,6 +33,7 @@ Breaking Changes: * Type Checker: Disallow arithmetic operations for boolean variables. * Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size. * Type Checker: Disallow specifying base constructor arguments multiple times in the same inheritance hierarchy. This was already the case in the experimental 0.5.0 mode. + * Type Checker: Disallow uninitialized storage variables. This was already the case in the experimental 0.5.0 mode. * Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``. * Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible. * Syntax Checker: Named return values in function types are an error. diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index 0d6fa033..75693bdd 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -306,48 +306,11 @@ independent copy of the state variable is created in memory and is another issue). The modifications to this independent copy do not carry back to ``data1`` or ``data2``. -A common mistake is to declare a local variable and assume that it will -be created in memory, although it will be created in storage:: - - /// THIS CONTRACT CONTAINS AN ERROR - - pragma solidity ^0.4.0; - - contract C { - uint someVariable; - uint[] data; - - function f() public { - uint[] x; - x.push(2); - data = x; - } - } - -The type of the local variable ``x`` is ``uint[] storage``, but since -storage is not dynamically allocated, it has to be assigned from -a state variable before it can be used. So no space in storage will be -allocated for ``x``, but instead it functions only as an alias for -a pre-existing variable in storage. - -What will happen is that the compiler interprets ``x`` as a storage -pointer and will make it point to the storage slot ``0`` by default. -This has the effect that ``someVariable`` (which resides at storage -slot ``0``) is modified by ``x.push(2)``. - -The correct way to do this is the following:: - - pragma solidity ^0.4.0; - - contract C { - uint someVariable; - uint[] data; - - function f() public { - uint[] x = data; - x.push(2); - } - } +.. warning:: + Prior to version 0.5.0, a common mistake was to declare a local variable and assume that it will + be created in memory, although it will be created in storage. Using such a variable without initializing + it could lead to unexpected behavior. Starting from 0.5.0, however, storage variables have to be initialized, + which should prevent these kinds of mistakes. ****************** Advanced Questions |