mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update documentation and Changelog.
This commit is contained in:
parent
46d6454b1f
commit
65631cffc2
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user