diff --git a/test/libsolidity/semanticTests/getters/array_mapping_struct.sol b/test/libsolidity/semanticTests/getters/array_mapping_struct.sol new file mode 100644 index 000000000..534dcd8a6 --- /dev/null +++ b/test/libsolidity/semanticTests/getters/array_mapping_struct.sol @@ -0,0 +1,29 @@ +contract C { + struct Y { + uint a; + uint b; + } + mapping(uint256 => Y)[] public m; + mapping(uint256 => Y)[3] public n; + constructor() public { + m.push(); + m.push(); + m[1][0].a = 1; + m[1][0].b = 2; + m[1][1].a = 3; + m[1][1].b = 4; + n[1][0].a = 7; + n[1][0].b = 8; + n[1][1].a = 9; + n[1][1].b = 10; + } +} +// ---- +// m(uint256,uint256): 0, 0 -> 0x00, 0x00 +// m(uint256,uint256): 1, 0 -> 1, 2 +// m(uint256,uint256): 1, 1 -> 3, 4 +// m(uint256,uint256): 1, 2 -> 0x00, 0x00 +// n(uint256,uint256): 0, 0 -> 0x00, 0x00 +// n(uint256,uint256): 1, 0 -> 7, 8 +// n(uint256,uint256): 1, 1 -> 9, 0x0a +// n(uint256,uint256): 1, 2 -> 0x00, 0x00 diff --git a/test/libsolidity/semanticTests/getters/mapping_array_struct.sol b/test/libsolidity/semanticTests/getters/mapping_array_struct.sol new file mode 100644 index 000000000..2b237c4df --- /dev/null +++ b/test/libsolidity/semanticTests/getters/mapping_array_struct.sol @@ -0,0 +1,27 @@ +contract C { + struct Y { + uint a; + uint b; + } + mapping(uint256 => Y[]) public m; + mapping(uint256 => Y[3]) public n; + constructor() public { + m[1].push().a = 1; + m[1][0].b = 2; + m[1].push().a = 3; + m[1][1].b = 4; + n[1][0].a = 7; + n[1][0].b = 8; + n[1][1].a = 9; + n[1][1].b = 10; + } +} +// ---- +// m(uint256,uint256): 0, 0 -> FAILURE +// m(uint256,uint256): 1, 0 -> 1, 2 +// m(uint256,uint256): 1, 1 -> 3, 4 +// m(uint256,uint256): 1, 2 -> FAILURE +// n(uint256,uint256): 0, 0 -> 0x00, 0x00 +// n(uint256,uint256): 1, 0 -> 7, 8 +// n(uint256,uint256): 1, 1 -> 9, 0x0a +// n(uint256,uint256): 1, 2 -> 0x00, 0x00 diff --git a/test/libsolidity/semanticTests/getters/mapping_of_string.sol b/test/libsolidity/semanticTests/getters/mapping_of_string.sol new file mode 100644 index 000000000..ea0a8b8f8 --- /dev/null +++ b/test/libsolidity/semanticTests/getters/mapping_of_string.sol @@ -0,0 +1,18 @@ +contract C { + mapping(string => uint8[3]) public x; + constructor() public { + x["abc"][0] = 1; + x["abc"][2] = 3; + x["abc"][1] = 2; + x["def"][1] = 9; + } +} +// ==== +// compileViaYul: also +// ---- +// x(string,uint256): 0x40, 0, 3, "abc" -> 1 +// x(string,uint256): 0x40, 1, 3, "abc" -> 2 +// x(string,uint256): 0x40, 2, 3, "abc" -> 3 +// x(string,uint256): 0x40, 0, 3, "def" -> 0x00 +// x(string,uint256): 0x40, 1, 3, "def" -> 9 +// x(string,uint256): 0x40, 2, 3, "def" -> 0x00 diff --git a/test/libsolidity/semanticTests/getters/struct_with_bytes.sol b/test/libsolidity/semanticTests/getters/struct_with_bytes.sol new file mode 100644 index 000000000..2bbd7e8b8 --- /dev/null +++ b/test/libsolidity/semanticTests/getters/struct_with_bytes.sol @@ -0,0 +1,18 @@ +contract C { + struct S { + uint a; + bytes b; + mapping(uint => uint) c; + uint[] d; + } + uint shifter; + S public s; + constructor() public { + s.a = 7; + s.b = "abc"; + s.c[0] = 9; + s.d.push(10); + } +} +// ---- +// s() -> 7, 0x40, 3, 0x6162630000000000000000000000000000000000000000000000000000000000