diff --git a/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_calldata_to_memory.sol b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_calldata_to_memory.sol new file mode 100644 index 000000000..8ccc30936 --- /dev/null +++ b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_calldata_to_memory.sol @@ -0,0 +1,16 @@ +pragma abicoder v2; + +contract C { + struct S { + uint8[1] x; + uint8[] y; + } + + function test(S calldata s) public returns (S memory) { + return s; + } +} + +// ---- +// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11 -> 0x20, 3, 0x40, 2, 7, 11 +// test((uint8[1],uint8[])): 0x20, 3, 0x40, 3, 17, 19, 23 -> 0x20, 3, 0x40, 3, 17, 19, 23 diff --git a/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_calldata_to_storage.sol b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_calldata_to_storage.sol new file mode 100644 index 000000000..fa67deb2c --- /dev/null +++ b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_calldata_to_storage.sol @@ -0,0 +1,22 @@ +pragma abicoder v2; + +contract C { + struct S { + uint8[1] x; + uint8[] y; + } + + S s; + + function test(S calldata src) public { + s = src; + + require(s.x[0] == 3); + require(s.y.length == 2); + require(s.y[0] == 7); + require(s.y[1] == 11); + } +} + +// ---- +// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11 diff --git a/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_memory_to_memory.sol b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_memory_to_memory.sol new file mode 100644 index 000000000..c340289ad --- /dev/null +++ b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_memory_to_memory.sol @@ -0,0 +1,16 @@ +pragma abicoder v2; + +contract C { + struct S { + uint8[1] x; + uint8[] y; + } + + function test(S memory s) public returns (S memory r) { + return r; + } +} + +// ---- +// test((uint8[1],uint8[])): 0x20, 3, 0x40, 2, 7, 11 -> 0x20, 0, 0x40, 0 +// test((uint8[1],uint8[])): 0x20, 3, 0x40, 3, 17, 19, 23 -> 0x20, 0, 0x40, 0 diff --git a/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_storage_to_storage.sol b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_storage_to_storage.sol new file mode 100644 index 000000000..3f29790d8 --- /dev/null +++ b/test/libsolidity/semanticTests/structs/copy_struct_with_nested_array_from_storage_to_storage.sol @@ -0,0 +1,27 @@ +contract C { + struct S { + uint8[1] x; + uint8[] y; + } + + S src; + S dst; + + constructor() { + src.x = [3]; + src.y.push(7); + src.y.push(11); + } + + function test() public { + dst = src; + + require(dst.x[0] == 3); + require(dst.y.length == 2); + require(dst.y[0] == 7); + require(dst.y[1] == 11); + } +} + +// ---- +// test()