Merge pull request #10691 from ethereum/arrayCopyIRCheck

Adding more tests for array copying.
This commit is contained in:
Đorđe Mijović 2020-12-28 14:05:46 +01:00 committed by GitHub
commit 8e9a5a02c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,19 @@
pragma abicoder v2;
contract C {
uint[][] a;
function f() public returns (uint[][] memory) {
a.push();
a.push();
a[0].push(0);
a[0].push(1);
a[1].push(2);
a[1].push(3);
uint[][] memory m = a;
return m;
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x20, 2, 0x40, 0xa0, 2, 0, 1, 2, 2, 3

View File

@ -0,0 +1,11 @@
pragma abicoder v2;
contract C {
function f(bytes[] calldata c) external returns (bytes[] memory) {
return c;
}
}
// ====
// compileViaYul: also
// ----
// f(bytes[]): 0x20, 2, 0x60, 0x60, 0x20, 2, "ab" -> 0x20, 2, 0x40, 0x80, 2, "ab", 2, "ab"

View File

@ -0,0 +1,13 @@
pragma abicoder v2;
contract C {
bytes10[] s;
function f(bytes8[] calldata c) external returns (uint256, bytes10, bytes10, bytes10) {
s = c;
return (s.length, s[0], s[1], s[2]);
}
}
// ====
// compileViaYul: also
// ----
// f(bytes8[]): 0x20, 3, "abcd", "bcde", "cdef" -> 3, "abcd", "bcde", "cdef"

View File

@ -0,0 +1,22 @@
pragma abicoder v2;
contract C {
bytes[] s;
function f() external returns (uint256) {
bytes[] memory m = new bytes[](3);
m[0] = "ab"; m[1] = "cde"; m[2] = "fghij";
s = m;
assert(s.length == m.length);
for (uint i = 0; i < s.length; ++i) {
assert(s[i].length == m[i].length);
for (uint j = 0; j < s[i].length; ++j) {
assert(s[i][j] == m[i][j]);
}
}
return s.length;
}
}
// ====
// compileViaYul: also
// ----
// f() -> 3

View File

@ -0,0 +1,17 @@
pragma abicoder v2;
contract C {
bytes10[] s;
function f() external returns (uint256, bytes10, bytes10, bytes10) {
bytes4[] memory m = new bytes4[](3);
m[0] = "abcd";
m[1] = "bcde";
m[2] = "cdef";
s = m;
return (s.length, s[0], s[1], s[2]);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 3, "abcd", "bcde", "cdef"

View File

@ -0,0 +1,10 @@
pragma abicoder v2;
contract C {
function f(bytes8[] calldata c) external returns (uint256, bytes10, bytes10, bytes10) {
bytes10[] memory m = c;
return (m.length, m[0], m[1], m[2]);
}
}
// ----
// TypeError 9574: (134-156): Type bytes8[] calldata is not implicitly convertible to expected type bytes10[] memory.

View File

@ -0,0 +1,14 @@
pragma abicoder v2;
contract C {
bytes8[] s;
function f() external returns (uint256, bytes10, bytes10, bytes10) {
s.push("abcd");
s.push("bcde");
s.push("cdef");
bytes10[] memory m = s;
return (m.length, m[0], m[1], m[2]);
}
}
// ----
// TypeError 9574: (203-225): Type bytes8[] storage ref is not implicitly convertible to expected type bytes10[] memory.