mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Initial introduction of array slices with partial implementation for dynamic calldata arrays.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
function f(bytes calldata x) external pure {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(bytes memory x) public pure {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (66-72): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
bytes x;
|
||||
function f() public view {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (65-71): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
function f(uint256[] calldata x) external pure {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f(uint256[] calldata x) external pure {
|
||||
x[1:2][0];
|
||||
x[1:][0];
|
||||
x[1:][1:2][0];
|
||||
x[1:2][1:][0];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(bytes calldata x) external {
|
||||
bytes memory y = x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (65-88): Type bytes calldata slice is not implicitly convertible to expected type bytes memory.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(uint256[] calldata x) external pure {
|
||||
abi.encode(x[1:2]);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (85-91): This type cannot be encoded.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(bytes calldata x) external {
|
||||
return this.f(x[1:2]);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (79-85): Invalid type for argument in function call. Invalid implicit conversion from bytes calldata slice to bytes memory requested.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(uint256[42] calldata x) external pure {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (76-82): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(uint256[] memory x) public pure {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (70-76): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(uint256[42] memory x) public pure {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (72-78): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
1[1:];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (52-57): Index range access is only possible for arrays and array slices.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes memory y;
|
||||
y[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (76-82): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
string memory y;
|
||||
y[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (77-83): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
""[1:];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (52-58): Index range access is only possible for arrays and array slices.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
uint256[] x;
|
||||
function f() public view {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (69-75): Index range access is only supported for dynamic calldata arrays.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
uint256[42] x;
|
||||
function f() public view {
|
||||
x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-77): Index range access is only supported for dynamic calldata arrays.
|
||||
Reference in New Issue
Block a user