Initial introduction of array slices with partial implementation for dynamic calldata arrays.

This commit is contained in:
Daniel Kirchner
2019-09-13 10:57:53 +02:00
parent 50ce3b0ac8
commit 4782c800ec
50 changed files with 659 additions and 105 deletions
@@ -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.