aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-30 19:30:09 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-05-16 09:52:24 +0800
commit6c8f78fb8ff99c5d28669fa7383a25b8c8523915 (patch)
tree77c6fa1dfe65d50a55e487ed0e3732d93a7bf00b
parentc781baf7336af55abc33e1b63e6fc99a7e555d78 (diff)
downloaddexon-solidity-6c8f78fb8ff99c5d28669fa7383a25b8c8523915.tar
dexon-solidity-6c8f78fb8ff99c5d28669fa7383a25b8c8523915.tar.gz
dexon-solidity-6c8f78fb8ff99c5d28669fa7383a25b8c8523915.tar.bz2
dexon-solidity-6c8f78fb8ff99c5d28669fa7383a25b8c8523915.tar.lz
dexon-solidity-6c8f78fb8ff99c5d28669fa7383a25b8c8523915.tar.xz
dexon-solidity-6c8f78fb8ff99c5d28669fa7383a25b8c8523915.tar.zst
dexon-solidity-6c8f78fb8ff99c5d28669fa7383a25b8c8523915.zip
Update documentation for multi variable declaration statement.
-rw-r--r--docs/control-structures.rst19
-rw-r--r--docs/frequently-asked-questions.rst4
-rw-r--r--docs/grammar.txt2
-rw-r--r--docs/solidity-by-example.rst6
4 files changed, 16 insertions, 15 deletions
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index f18e1e10..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,12 +287,8 @@ 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).
@@ -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
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index 6a2fe685..ca5a1aee 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -203,7 +203,7 @@ situation.
If you do not want to throw, you can return a pair::
- pragma solidity ^0.4.16;
+ pragma solidity >0.4.23 <0.5.0;
contract C {
uint[] counters;
@@ -219,7 +219,7 @@ If you do not want to throw, you can return a pair::
}
function checkCounter(uint index) public view {
- var (counter, error) = getCounter(index);
+ (uint counter, bool error) = getCounter(index);
if (error) {
// ...
} else {
diff --git a/docs/grammar.txt b/docs/grammar.txt
index 565db9a4..0dda4f49 100644
--- a/docs/grammar.txt
+++ b/docs/grammar.txt
@@ -78,7 +78,7 @@ Break = 'break'
Return = 'return' Expression?
Throw = 'throw'
EmitStatement = 'emit' FunctionCall
-VariableDefinition = ('var' IdentifierList | VariableDeclaration) ( '=' Expression )?
+VariableDefinition = ('var' IdentifierList | VariableDeclaration | '(' VariableDeclaration? (',' VariableDeclaration? )* ')' ) ( '=' Expression )?
IdentifierList = '(' ( Identifier? ',' )* Identifier? ')'
// Precedence by order (see github.com/ethereum/solidity/pull/732)
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index f6038f7d..2b3d4b48 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -388,7 +388,7 @@ high or low invalid bids.
::
- pragma solidity ^0.4.22;
+ pragma solidity >0.4.23 <0.5.0;
contract BlindAuction {
struct Bid {
@@ -467,8 +467,8 @@ high or low invalid bids.
uint refund;
for (uint i = 0; i < length; i++) {
- var bid = bids[msg.sender][i];
- var (value, fake, secret) =
+ Bid storage bid = bids[msg.sender][i];
+ (uint value, bool fake, bytes32 secret) =
(_values[i], _fake[i], _secret[i]);
if (bid.blindedBid != keccak256(value, fake, secret)) {
// Bid was not actually revealed.