mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds syntax tests, documentation and changelog entry.
Refines comment for array utility function.
This commit is contained in:
parent
34b5eca1f8
commit
98d52beba3
@ -1,5 +1,7 @@
|
|||||||
### 0.5.0 (unreleased)
|
### 0.5.0 (unreleased)
|
||||||
|
|
||||||
|
Language Features:
|
||||||
|
* General: Support ``pop()`` for storage arrays.
|
||||||
|
|
||||||
Breaking Changes:
|
Breaking Changes:
|
||||||
* Disallow conversions between bytesX and uintY of different size.
|
* Disallow conversions between bytesX and uintY of different size.
|
||||||
|
@ -682,7 +682,7 @@ possible:
|
|||||||
It is planned to remove this restriction in the future but currently creates
|
It is planned to remove this restriction in the future but currently creates
|
||||||
some complications because of how arrays are passed in the ABI.
|
some complications because of how arrays are passed in the ABI.
|
||||||
|
|
||||||
.. index:: ! array;length, length, push, !array;push
|
.. index:: ! array;length, length, push, pop, !array;push, !array;pop
|
||||||
|
|
||||||
Members
|
Members
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
@ -693,6 +693,8 @@ Members
|
|||||||
``.length`` member. This does not happen automatically when attempting to access elements outside the current length. The size of memory arrays is fixed (but dynamic, i.e. it can depend on runtime parameters) once they are created.
|
``.length`` member. This does not happen automatically when attempting to access elements outside the current length. The size of memory arrays is fixed (but dynamic, i.e. it can depend on runtime parameters) once they are created.
|
||||||
**push**:
|
**push**:
|
||||||
Dynamic storage arrays and ``bytes`` (not ``string``) have a member function called ``push`` that can be used to append an element at the end of the array. The function returns the new length.
|
Dynamic storage arrays and ``bytes`` (not ``string``) have a member function called ``push`` that can be used to append an element at the end of the array. The function returns the new length.
|
||||||
|
**pop**:
|
||||||
|
Dynamic storage arrays and ``bytes`` (not ``string``) have a member function called ``pop`` that can be used to remove an element from the end of the array.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
It is not yet possible to use arrays of arrays in external functions.
|
It is not yet possible to use arrays of arrays in external functions.
|
||||||
|
@ -840,7 +840,7 @@ void ArrayUtils::popStorageArrayElement(ArrayType const& _type) const
|
|||||||
let length := and(div(slot_value, 2), 0x1f)
|
let length := and(div(slot_value, 2), 0x1f)
|
||||||
if iszero(length) { invalid() }
|
if iszero(length) { invalid() }
|
||||||
|
|
||||||
// Zero-out the suffix inlcluding the least significant byte.
|
// Zero-out the suffix including the least significant byte.
|
||||||
let mask := sub(exp(0x100, sub(33, length)), 1)
|
let mask := sub(exp(0x100, sub(33, length)), 1)
|
||||||
length := sub(length, 1)
|
length := sub(length, 1)
|
||||||
slot_value := or(and(not(mask), slot_value), mul(length, 2))
|
slot_value := or(and(not(mask), slot_value), mul(length, 2))
|
||||||
|
@ -73,7 +73,7 @@ public:
|
|||||||
/// Stack pre: reference (excludes byte offset)
|
/// Stack pre: reference (excludes byte offset)
|
||||||
/// Stack post: new_length
|
/// Stack post: new_length
|
||||||
void incrementDynamicArraySize(ArrayType const& _type) const;
|
void incrementDynamicArraySize(ArrayType const& _type) const;
|
||||||
/// Decrements the size of a dynamic array by one if length is nonzero. Returns otherwise.
|
/// Decrements the size of a dynamic array by one if length is nonzero. Causes an invalid instruction otherwise.
|
||||||
/// Clears the removed data element. In case of a byte array, this might move the data.
|
/// Clears the removed data element. In case of a byte array, this might move the data.
|
||||||
/// Stack pre: reference
|
/// Stack pre: reference
|
||||||
/// Stack post:
|
/// Stack post:
|
||||||
|
7
test/libsolidity/syntaxTests/array/array_pop.sol
Normal file
7
test/libsolidity/syntaxTests/array/array_pop.sol
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
contract C {
|
||||||
|
uint[] data;
|
||||||
|
function test() public {
|
||||||
|
data.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
8
test/libsolidity/syntaxTests/array/array_pop_arg.sol
Normal file
8
test/libsolidity/syntaxTests/array/array_pop_arg.sol
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
uint[] data;
|
||||||
|
function test() public {
|
||||||
|
data.pop(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (65-76): Wrong argument count for function call: 1 arguments given but expected 0.
|
7
test/libsolidity/syntaxTests/array/bytes_pop.sol
Normal file
7
test/libsolidity/syntaxTests/array/bytes_pop.sol
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
contract C {
|
||||||
|
bytes data;
|
||||||
|
function test() public {
|
||||||
|
data.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
function test() public {
|
||||||
|
uint[] memory data;
|
||||||
|
data.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (74-82): Member "pop" is not available in uint256[] memory outside of storage.
|
8
test/libsolidity/syntaxTests/array/no_array_pop.sol
Normal file
8
test/libsolidity/syntaxTests/array/no_array_pop.sol
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
uint data;
|
||||||
|
function test() public {
|
||||||
|
data.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (63-71): Member "pop" not found or not visible after argument-dependent lookup in uint256
|
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
uint[3] data;
|
||||||
|
function test() public {
|
||||||
|
data.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (66-74): Member "pop" not found or not visible after argument-dependent lookup in uint256[3] storage ref
|
8
test/libsolidity/syntaxTests/array/string_pop.sol
Normal file
8
test/libsolidity/syntaxTests/array/string_pop.sol
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
string data;
|
||||||
|
function test() public {
|
||||||
|
data.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (65-73): Member "pop" not found or not visible after argument-dependent lookup in string storage ref
|
Loading…
Reference in New Issue
Block a user