solidity/test/libsolidity/semanticTests/structs/memory_structs_nested_load.sol

72 lines
1.3 KiB
Solidity

contract Test {
struct S {
uint8 x;
uint16 y;
uint256 z;
}
struct X {
uint8 x;
S s;
uint8[2] a;
}
X m_x;
function load()
public
returns (
uint256 a,
uint256 x,
uint256 y,
uint256 z,
uint256 a1,
uint256 a2
)
{
m_x.x = 1;
m_x.s.x = 2;
m_x.s.y = 3;
m_x.s.z = 4;
m_x.a[0] = 5;
m_x.a[1] = 6;
X memory d = m_x;
a = d.x;
x = d.s.x;
y = d.s.y;
z = d.s.z;
a1 = d.a[0];
a2 = d.a[1];
}
function store()
public
returns (
uint256 a,
uint256 x,
uint256 y,
uint256 z,
uint256 a1,
uint256 a2
)
{
X memory d;
d.x = 1;
d.s.x = 2;
d.s.y = 3;
d.s.z = 4;
d.a[0] = 5;
d.a[1] = 6;
m_x = d;
a = m_x.x;
x = m_x.s.x;
y = m_x.s.y;
z = m_x.s.z;
a1 = m_x.a[0];
a2 = m_x.a[1];
}
}
// ====
// compileViaYul: also
// ----
// load() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
// store() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06