mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Tests for copying nested array of structs between data locations
This commit is contained in:
parent
c4d97120bd
commit
dfe8fce369
@ -0,0 +1,25 @@
|
||||
pragma abicoder v2;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint8 x;
|
||||
uint8 y;
|
||||
}
|
||||
|
||||
function test1(S[1][2] calldata a) public returns (S[1][2] memory) {
|
||||
return a;
|
||||
}
|
||||
|
||||
function test2(S[1][] calldata a) public returns (S[1][] memory) {
|
||||
return a;
|
||||
}
|
||||
|
||||
function test3(S[][2] calldata a) public returns (S[][2] memory) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// test1((uint8,uint8)[1][2]): 1, 2, 3, 4 -> 1, 2, 3, 4
|
||||
// test2((uint8,uint8)[1][]): 0x20, 3, 7, 11, 13, 17, 19, 23 -> 0x20, 3, 7, 11, 13, 17, 19, 23
|
||||
// test3((uint8,uint8)[][2]): 0x20, 0x40, 0xa0, 1, 3, 7, 2, 11, 13, 17, 19 -> 0x20, 0x40, 0xa0, 1, 3, 7, 2, 11, 13, 17, 19
|
@ -0,0 +1,25 @@
|
||||
pragma abicoder v2;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint8 x;
|
||||
uint8 y;
|
||||
}
|
||||
|
||||
function test1(S[1][2] memory a) public returns (S[1][2] memory r) {
|
||||
r = a;
|
||||
}
|
||||
|
||||
function test2(S[1][] memory a) public returns (S[1][] memory r) {
|
||||
r = a;
|
||||
}
|
||||
|
||||
function test3(S[][2] memory a) public returns (S[][2] memory r) {
|
||||
r = a;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// test1((uint8,uint8)[1][2]): 1, 2, 3, 4 -> 1, 2, 3, 4
|
||||
// test2((uint8,uint8)[1][]): 0x20, 3, 7, 11, 13, 17, 19, 23 -> 0x20, 3, 7, 11, 13, 17, 19, 23
|
||||
// test3((uint8,uint8)[][2]): 0x20, 0x40, 0xa0, 1, 3, 7, 2, 11, 13, 17, 19 -> 0x20, 0x40, 0xa0, 1, 3, 7, 2, 11, 13, 17, 19
|
@ -0,0 +1,70 @@
|
||||
pragma abicoder v2;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint8 x;
|
||||
uint8 y;
|
||||
}
|
||||
|
||||
S[][] src1;
|
||||
S[][1] src2;
|
||||
S[1][] src3;
|
||||
|
||||
S[][] dst1;
|
||||
S[][1] dst2;
|
||||
S[1][] dst3;
|
||||
|
||||
constructor() {
|
||||
src1 = new S[][](1);
|
||||
src1[0].push(S({x: 3, y: 7}));
|
||||
src1[0].push(S({x: 11, y: 13}));
|
||||
|
||||
src2[0].push(S({x: 3, y: 7}));
|
||||
src2[0].push(S({x: 11, y: 13}));
|
||||
src2[0].push(S({x: 17, y: 19}));
|
||||
|
||||
src3.push([S({x: 3, y: 7})]);
|
||||
src3.push([S({x: 11, y: 13})]);
|
||||
}
|
||||
|
||||
function test1() public {
|
||||
dst1 = src1;
|
||||
|
||||
require(dst1.length == 1);
|
||||
require(dst1[0][0].x == src1[0][0].x);
|
||||
require(dst1[0][0].y == src1[0][0].y);
|
||||
require(dst1[0][1].x == src1[0][1].x);
|
||||
require(dst1[0][1].y == src1[0][1].y);
|
||||
}
|
||||
|
||||
function test2() public {
|
||||
dst2 = src2;
|
||||
|
||||
require(dst2[0].length == 3);
|
||||
require(dst2[0][0].x == src2[0][0].x);
|
||||
require(dst2[0][0].y == src2[0][0].y);
|
||||
require(dst2[0][1].x == src2[0][1].x);
|
||||
require(dst2[0][1].y == src2[0][1].y);
|
||||
require(dst2[0][2].x == src2[0][2].x);
|
||||
require(dst2[0][2].y == src2[0][2].y);
|
||||
}
|
||||
|
||||
function test3() public {
|
||||
dst3 = src3;
|
||||
|
||||
require(dst3.length == 2);
|
||||
require(dst3[0][0].x == src3[0][0].x);
|
||||
require(dst3[0][0].y == src3[0][0].y);
|
||||
require(dst3[1][0].x == src3[1][0].x);
|
||||
require(dst3[1][0].y == src3[1][0].y);
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// test1()
|
||||
// gas irOptimized: 123279
|
||||
// test2()
|
||||
// gas irOptimized: 123073
|
||||
// test3()
|
Loading…
Reference in New Issue
Block a user