mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Implementing dynamic array push for arrays of structs.
This commit is contained in:
committed by
chriseth
parent
b06936b11c
commit
85b8325f0b
@@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
uint8 b = 23;
|
||||
uint120[][] s;
|
||||
uint8 a = 17;
|
||||
function f(uint120[] calldata c) public returns(uint120) {
|
||||
s.push(c);
|
||||
assert(s.length == 1);
|
||||
assert(s[0].length == c.length);
|
||||
assert(s[0].length > 0);
|
||||
return s[0][0];
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint120[]): 0x20, 3, 1, 2, 3 -> 1
|
||||
@@ -0,0 +1,19 @@
|
||||
contract C {
|
||||
uint8 b = 23;
|
||||
uint120[][] s;
|
||||
uint8 a = 17;
|
||||
function f() public returns(uint120) {
|
||||
delete s;
|
||||
uint120[] memory m = new uint120[](3);
|
||||
m[0] = 1;
|
||||
s.push(m);
|
||||
assert(s.length == 1);
|
||||
assert(s[0].length == m.length);
|
||||
assert(s[0].length > 0);
|
||||
return s[0][0];
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 1
|
||||
@@ -18,6 +18,7 @@ contract c {
|
||||
return (data[0].a, data[0].b, data[0].c[2], data[0].d[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 2, 3, 4, 5
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
pragma abicoder v2;
|
||||
|
||||
contract c {
|
||||
struct S {
|
||||
uint16 a;
|
||||
uint16 b;
|
||||
uint16[3] c;
|
||||
uint16[] d;
|
||||
}
|
||||
S[] data;
|
||||
|
||||
function test(S calldata c) public returns (uint16, uint16, uint16, uint16) {
|
||||
data.push(c);
|
||||
return (data[0].a, data[0].b, data[0].c[2], data[0].d[2]);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test((uint16, uint16, uint16[3], uint16[])): 0x20, 2, 3, 0, 0, 4, 0xC0, 4, 0, 0, 5, 0, 0 -> 2, 3, 4, 5
|
||||
Reference in New Issue
Block a user