aboutsummaryrefslogtreecommitdiffstats
path: root/docs/control-structures.rst
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-05-16 20:43:57 +0800
committerGitHub <noreply@github.com>2018-05-16 20:43:57 +0800
commite67f0147998a9e3835ed3ce8bf6a0a0c634216c5 (patch)
treeb9c0b7d41cd9f78ae3404704a888da30e767edbe /docs/control-structures.rst
parent124ca40dc525a987a88176c6e5170978e82fa290 (diff)
parent1e45d3ab2e0ca688c2ae48ab657f11496ccebc12 (diff)
downloaddexon-solidity-e67f0147998a9e3835ed3ce8bf6a0a0c634216c5.tar
dexon-solidity-e67f0147998a9e3835ed3ce8bf6a0a0c634216c5.tar.gz
dexon-solidity-e67f0147998a9e3835ed3ce8bf6a0a0c634216c5.tar.bz2
dexon-solidity-e67f0147998a9e3835ed3ce8bf6a0a0c634216c5.tar.lz
dexon-solidity-e67f0147998a9e3835ed3ce8bf6a0a0c634216c5.tar.xz
dexon-solidity-e67f0147998a9e3835ed3ce8bf6a0a0c634216c5.tar.zst
dexon-solidity-e67f0147998a9e3835ed3ce8bf6a0a0c634216c5.zip
Merge pull request #4148 from ethereum/develop
Merge develop into release for 0.4.24
Diffstat (limited to 'docs/control-structures.rst')
-rw-r--r--docs/control-structures.rst31
1 files changed, 16 insertions, 15 deletions
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index f3c351dd..7849d15a 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -272,9 +272,12 @@ Assignment
Destructuring Assignments and Returning Multiple Values
-------------------------------------------------------
-Solidity internally allows tuple types, i.e. a list of objects of potentially different types whose size is a constant at compile-time. Those tuples can be used to return multiple values at the same time and also assign them to multiple variables (or LValues in general) at the same time::
+Solidity internally allows tuple types, i.e. a list of objects of potentially different types whose size is a constant at compile-time. Those tuples can be used to return multiple values at the same time.
+These can then either be assigned to newly declared variables or to pre-existing variables (or LValues in general):
- pragma solidity ^0.4.16;
+::
+
+ pragma solidity >0.4.23 <0.5.0;
contract C {
uint[] data;
@@ -284,21 +287,12 @@ Solidity internally allows tuple types, i.e. a list of objects of potentially di
}
function g() public {
- // Variables declared with type
- uint x;
- bool b;
- uint y;
- // Tuple values can be assigned to these pre-existing variables
- (x, b, y) = f();
+ // Variables declared with type and assigned from the returned tuple.
+ (uint x, bool b, uint y) = f();
// Common trick to swap values -- does not work for non-value storage types.
(x, y) = (y, x);
// Components can be left out (also for variable declarations).
- // If the tuple ends in an empty component,
- // the rest of the values are discarded.
- (data.length,) = f(); // Sets the length to 7
- // The same can be done on the left side.
- // If the tuple begins in an empty component, the beginning values are discarded.
- (,data[3]) = f(); // Sets data[3] to 2
+ (data.length,,) = f(); // Sets the length to 7
// Components can only be left out at the left-hand-side of assignments, with
// one exception:
(x,) = (1,);
@@ -307,6 +301,11 @@ Solidity internally allows tuple types, i.e. a list of objects of potentially di
}
}
+.. note::
+ Prior to version 0.4.24 it was possible to assign to tuples of smaller size, either
+ filling up on the left or on the right side (which ever was empty). This is
+ now deprecated, both sides have to have the same number of components.
+
Complications for Arrays and Structs
------------------------------------
@@ -330,7 +329,9 @@ A variable declared anywhere within a function will be in scope for the *entire
(this will change soon, see below).
This happens because Solidity inherits its scoping rules from JavaScript.
This is in contrast to many languages where variables are only scoped where they are declared until the end of the semantic block.
-As a result, the following code is illegal and cause the compiler to throw an error, ``Identifier already declared``::
+As a result, the following code is illegal and cause the compiler to throw an error, ``Identifier already declared``:
+
+::
// This will not compile