From d05afb34d685e6a80759877ea275db0a83029da8 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 18 Sep 2019 15:36:45 +0200 Subject: [PATCH] Adjusts syntax tests to read-only array length. --- .../syntaxTests/array/calldata_resize.sol | 2 +- .../syntaxTests/array/length/cannot_be_assigned.sol | 8 ++++++++ .../array/length/cannot_be_assigned_mapping.sol | 8 ++++++++ .../array/length/cannot_be_assigned_struct.sol | 11 +++++++++++ .../syntaxTests/array/pop/calldata_pop.sol | 7 +++++++ .../libsolidity/syntaxTests/array/pop/memory_pop.sol | 8 ++++++++ .../syntaxTests/array/push/calldata_push.sol | 7 +++++++ .../syntaxTests/array/push/memory_push.sol | 8 ++++++++ .../219_memory_arrays_not_resizeable.sol | 2 +- .../viewPureChecker/array/access_to_array_push.sol | 7 +++++++ .../array/access_to_array_push_view.sol | 8 ++++++++ .../{ => array}/access_to_base_member_array.sol | 12 ++++-------- 12 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 test/libsolidity/syntaxTests/array/length/cannot_be_assigned.sol create mode 100644 test/libsolidity/syntaxTests/array/length/cannot_be_assigned_mapping.sol create mode 100644 test/libsolidity/syntaxTests/array/length/cannot_be_assigned_struct.sol create mode 100644 test/libsolidity/syntaxTests/array/pop/calldata_pop.sol create mode 100644 test/libsolidity/syntaxTests/array/pop/memory_pop.sol create mode 100644 test/libsolidity/syntaxTests/array/push/calldata_push.sol create mode 100644 test/libsolidity/syntaxTests/array/push/memory_push.sol create mode 100644 test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push.sol create mode 100644 test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol rename test/libsolidity/syntaxTests/viewPureChecker/{ => array}/access_to_base_member_array.sol (53%) diff --git a/test/libsolidity/syntaxTests/array/calldata_resize.sol b/test/libsolidity/syntaxTests/array/calldata_resize.sol index f923993c2..298d838aa 100644 --- a/test/libsolidity/syntaxTests/array/calldata_resize.sol +++ b/test/libsolidity/syntaxTests/array/calldata_resize.sol @@ -4,4 +4,4 @@ contract C { } } // ---- -// TypeError: (75-83): Calldata arrays cannot be resized. +// TypeError: (75-83): Member "length" is read-only and cannot be used to resize arrays. diff --git a/test/libsolidity/syntaxTests/array/length/cannot_be_assigned.sol b/test/libsolidity/syntaxTests/array/length/cannot_be_assigned.sol new file mode 100644 index 000000000..603f3ba38 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/cannot_be_assigned.sol @@ -0,0 +1,8 @@ +contract c { + uint[] storageArray; + function f() public { + storageArray.length = 3; + } +} +// ---- +// TypeError: (72-91): Member "length" is read-only and cannot be used to resize arrays. diff --git a/test/libsolidity/syntaxTests/array/length/cannot_be_assigned_mapping.sol b/test/libsolidity/syntaxTests/array/length/cannot_be_assigned_mapping.sol new file mode 100644 index 000000000..f20ae2227 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/cannot_be_assigned_mapping.sol @@ -0,0 +1,8 @@ +contract C { + mapping(uint => uint[]) map; + function f() public { + map[0].length = 4; + } +} +// ---- +// TypeError: (80-93): Member "length" is read-only and cannot be used to resize arrays. diff --git a/test/libsolidity/syntaxTests/array/length/cannot_be_assigned_struct.sol b/test/libsolidity/syntaxTests/array/length/cannot_be_assigned_struct.sol new file mode 100644 index 000000000..465e04b13 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/cannot_be_assigned_struct.sol @@ -0,0 +1,11 @@ +contract C { + struct S { + uint[] a; + } + S s; + function f() public { + s.a.length = 4; + } +} +// ---- +// TypeError: (95-105): Member "length" is read-only and cannot be used to resize arrays. diff --git a/test/libsolidity/syntaxTests/array/pop/calldata_pop.sol b/test/libsolidity/syntaxTests/array/pop/calldata_pop.sol new file mode 100644 index 000000000..ca11428ee --- /dev/null +++ b/test/libsolidity/syntaxTests/array/pop/calldata_pop.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint[] calldata x) external { + x.pop(); + } +} +// ---- +// TypeError: (66-71): Member "pop" is not available in uint256[] calldata outside of storage. diff --git a/test/libsolidity/syntaxTests/array/pop/memory_pop.sol b/test/libsolidity/syntaxTests/array/pop/memory_pop.sol new file mode 100644 index 000000000..8984341aa --- /dev/null +++ b/test/libsolidity/syntaxTests/array/pop/memory_pop.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + uint[] memory x; + x.pop(); + } +} +// ---- +// TypeError: (72-77): Member "pop" is not available in uint256[] memory outside of storage. diff --git a/test/libsolidity/syntaxTests/array/push/calldata_push.sol b/test/libsolidity/syntaxTests/array/push/calldata_push.sol new file mode 100644 index 000000000..fb46bf328 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/push/calldata_push.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint[] calldata x) external { + x.push(); + } +} +// ---- +// TypeError: (66-72): Member "push" is not available in uint256[] calldata outside of storage. diff --git a/test/libsolidity/syntaxTests/array/push/memory_push.sol b/test/libsolidity/syntaxTests/array/push/memory_push.sol new file mode 100644 index 000000000..5e0890e63 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/push/memory_push.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + uint[] memory x; + x.push(); + } +} +// ---- +// TypeError: (72-78): Member "push" is not available in uint256[] memory outside of storage. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/219_memory_arrays_not_resizeable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/219_memory_arrays_not_resizeable.sol index aba0fff48..dbba54aba 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/219_memory_arrays_not_resizeable.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/219_memory_arrays_not_resizeable.sol @@ -5,4 +5,4 @@ contract C { } } // ---- -// TypeError: (72-80): Memory arrays cannot be resized. +// TypeError: (72-80): Member "length" is read-only and cannot be used to resize arrays. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push.sol b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push.sol new file mode 100644 index 000000000..abf8036d0 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push.sol @@ -0,0 +1,7 @@ +contract A { + uint[] x; + function g() public returns (uint) { + return x.push(); + } +} +// ---- \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol new file mode 100644 index 000000000..c9fe1fe8e --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol @@ -0,0 +1,8 @@ +contract A { + uint[] x; + function f() public view returns (uint) { + return x.push(); + } +} +// ---- +// TypeError: (88-96): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_array.sol b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_base_member_array.sol similarity index 53% rename from test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_array.sol rename to test/libsolidity/syntaxTests/viewPureChecker/array/access_to_base_member_array.sol index 16a25d57c..9562c0689 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_array.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_base_member_array.sol @@ -3,9 +3,6 @@ contract A { } contract B is A { - function f() public view { - A.x.length = 2; - } function g() public pure returns (uint) { return A.x.length; } @@ -14,8 +11,7 @@ contract B is A { } } // ---- -// TypeError: (87-97): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError: (170-173): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError: (170-180): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError: (249-252): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError: (249-255): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (109-112): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (109-119): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (188-191): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". +// TypeError: (188-194): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".