From 16de7a04935ecee9c33392965f23dcfc775b799d Mon Sep 17 00:00:00 2001 From: mingchuan Date: Thu, 26 Jul 2018 12:06:56 +0800 Subject: New test cases. --- .../dataLocations/data_location_in_function_type.sol | 11 +++++++++++ .../external_function_return_parameters_no_data_location.sol | 5 +++++ .../function_parameters_with_data_location_fine.sol | 10 ++++++++++ .../function_return_parameters_with_data_location_fine.sol | 7 +++++++ .../dataLocations/function_type_array_as_reference_type.sol | 10 ++++++++++ .../internal_function_parameters_no_data_location.sol | 5 +++++ .../internal_function_return_parameters_no_data_location.sol | 5 +++++ .../library_function_parameters_with_data_location_fine.sol | 8 ++++++++ ...y_internal_function_return_parameters_no_data_location.sol | 5 +++++ .../library_private_function_parameters_no_data_location.sol | 5 +++++ ...ary_public_function_return_parameters_no_data_location.sol | 5 +++++ .../private_function_parameters_no_data_location.sol | 5 +++++ .../private_function_return_parameters_no_data_location.sol | 5 +++++ .../public_function_parameters_no_data_location.sol | 5 +++++ .../public_function_return_parameters_no_data_location.sol | 5 +++++ .../syntaxTests/nameAndTypeResolution/constant_mapping.sol | 8 ++++++++ .../mapping_array_data_location_function_param_external.sol | 6 ++++++ .../mapping/mapping_data_location_function_param_external.sol | 6 ++++++ .../mapping/mapping_data_location_function_param_internal.sol | 4 ++++ .../mapping/mapping_data_location_function_param_public.sol | 6 ++++++ 20 files changed, 126 insertions(+) create mode 100644 test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/externalFunction/external_function_return_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/function_parameters_with_data_location_fine.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/function_type_array_as_reference_type.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_return_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/libraries/library_function_parameters_with_data_location_fine.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/libraries/library_internal_function_return_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/libraries/library_private_function_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/libraries/library_public_function_return_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_no_data_location.sol create mode 100644 test/libsolidity/syntaxTests/nameAndTypeResolution/constant_mapping.sol create mode 100644 test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol create mode 100644 test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol create mode 100644 test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_internal.sol create mode 100644 test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol (limited to 'test') diff --git a/test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type.sol b/test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type.sol new file mode 100644 index 00000000..2a485581 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/data_location_in_function_type.sol @@ -0,0 +1,11 @@ +library L { + struct Nested { uint y; } + // data location specifier in function signature should be optional even if there are multiple choices + function a(function(Nested) external returns (uint)[] storage) external pure {} + function b(function(Nested calldata) external returns (uint)[] storage) external pure {} + function c(function(Nested memory) external returns (uint)[] storage) external pure {} + function d(function(Nested storage) external returns (uint)[] storage) external pure {} +} + +// ---- +// TypeError: (441-447): Location has to be calldata or memory for function type of external function. Remove the data location keyword to fix this error. diff --git a/test/libsolidity/syntaxTests/dataLocations/externalFunction/external_function_return_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/externalFunction/external_function_return_parameters_no_data_location.sol new file mode 100644 index 00000000..0ed954ed --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/externalFunction/external_function_return_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +contract C { + function i() external pure returns(uint[]) {} +} +// ---- +// TypeError: (52-58): Storage location must be "memory" for parameter in external function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/function_parameters_with_data_location_fine.sol b/test/libsolidity/syntaxTests/dataLocations/function_parameters_with_data_location_fine.sol new file mode 100644 index 00000000..da4a7354 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/function_parameters_with_data_location_fine.sol @@ -0,0 +1,10 @@ +contract C { + // Warning for no data location provided can be silenced with storage or memory. + function f(uint[] memory, uint[] storage) private pure {} + function g(uint[] memory, uint[] storage) internal pure {} + function h(uint[] memory) public pure {} + // No warning on external functions, because of default to calldata. + function i(uint[]) external pure {} + // No warning for events. + event e(uint[]); +} \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol b/test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol new file mode 100644 index 00000000..047b6b80 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol @@ -0,0 +1,7 @@ +contract C { + // Shows that the warning for no data location provided can be silenced with storage or memory. + function f() private pure returns(uint[] memory, uint[] storage b) { b = b; } + function g() internal pure returns(uint[] memory, uint[] storage b) { b = b; } + function h() public pure returns(uint[] memory) {} + function i() external pure returns(uint[] memory) {} +} \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/dataLocations/function_type_array_as_reference_type.sol b/test/libsolidity/syntaxTests/dataLocations/function_type_array_as_reference_type.sol new file mode 100644 index 00000000..a5d6af34 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/function_type_array_as_reference_type.sol @@ -0,0 +1,10 @@ +contract C { + struct Nested { uint y; } + // ensure that we consider array of function pointers as reference type + function a(function(Nested) external returns (uint)[]) public pure {} + function b(function(Nested) external returns (uint)[] storage) public pure {} + function c(function(Nested) external returns (uint)[] memory) public pure {} + function d(function(Nested) external returns (uint)[] calldata) public pure {} +} +// ---- +// TypeError: (208-250): Location has to be memory for public function. Remove the data location keyword to fix this error. diff --git a/test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_parameters_no_data_location.sol new file mode 100644 index 00000000..1ec530a9 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +contract C { + function g(uint[]) internal pure {} +} +// ---- +// TypeError: (28-34): Storage location must be "storage" or "memory" for parameter in internal function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_return_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_return_parameters_no_data_location.sol new file mode 100644 index 00000000..243151f0 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/internalFunction/internal_function_return_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +contract C { + function g() internal pure returns(uint[]) {} +} +// ---- +// TypeError: (52-58): Storage location must be "storage" or "memory" for parameter in internal function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/libraries/library_function_parameters_with_data_location_fine.sol b/test/libsolidity/syntaxTests/dataLocations/libraries/library_function_parameters_with_data_location_fine.sol new file mode 100644 index 00000000..f778b7ed --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraries/library_function_parameters_with_data_location_fine.sol @@ -0,0 +1,8 @@ +library L { + // Warning for no data location provided can be silenced with storage or memory. + function f(uint[] memory, uint[] storage) private pure {} + function g(uint[] memory, uint[] storage) internal pure {} + function h(uint[] memory) public pure {} + // No warning on external functions, because of default to calldata. + function i(uint[]) external pure {} +} \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/dataLocations/libraries/library_internal_function_return_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/libraries/library_internal_function_return_parameters_no_data_location.sol new file mode 100644 index 00000000..8218dded --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraries/library_internal_function_return_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +library L { + function g(uint[]) internal pure {} +} +// ---- +// TypeError: (27-33): Storage location must be "storage" or "memory" for parameter in internal function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/libraries/library_private_function_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/libraries/library_private_function_parameters_no_data_location.sol new file mode 100644 index 00000000..79307cd0 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraries/library_private_function_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +library L { + function h(uint[]) public pure {} +} +// ---- +// TypeError: (27-33): Storage location must be "storage" or "memory" for parameter in public function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/libraries/library_public_function_return_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/libraries/library_public_function_return_parameters_no_data_location.sol new file mode 100644 index 00000000..79307cd0 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/libraries/library_public_function_return_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +library L { + function h(uint[]) public pure {} +} +// ---- +// TypeError: (27-33): Storage location must be "storage" or "memory" for parameter in public function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_no_data_location.sol new file mode 100644 index 00000000..2f4e2a34 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +contract C { + function f(uint[]) private pure {} +} +// ---- +// TypeError: (28-34): Storage location must be "storage" or "memory" for parameter in private function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_no_data_location.sol new file mode 100644 index 00000000..5356f944 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/privateFunction/private_function_return_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +contract C { + function f() private pure returns(uint[]) {} +} +// ---- +// TypeError: (51-57): Storage location must be "storage" or "memory" for parameter in private function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_parameters_no_data_location.sol new file mode 100644 index 00000000..47d9c47b --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +contract C { + function h(uint[]) public pure {} +} +// ---- +// TypeError: (28-34): Storage location must be "memory" for parameter in public function, but none was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_no_data_location.sol b/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_no_data_location.sol new file mode 100644 index 00000000..42980c51 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/publicFunction/public_function_return_parameters_no_data_location.sol @@ -0,0 +1,5 @@ +contract C { + function h() public pure returns(uint[]) {} +} +// ---- +// TypeError: (50-56): Storage location must be "memory" for parameter in public function, but none was given. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/constant_mapping.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/constant_mapping.sol new file mode 100644 index 00000000..61c0cc17 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/constant_mapping.sol @@ -0,0 +1,8 @@ +contract C { + // This should probably have a better error message at some point. + // Constant mappings should not be possible in general. + mapping(uint => uint) constant x; +} +// ---- +// TypeError: (148-180): Constants of non-value type not yet implemented. +// TypeError: (148-180): Uninitialized "constant" variable. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol new file mode 100644 index 00000000..9b96fd3a --- /dev/null +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol @@ -0,0 +1,6 @@ +contract c { + function f1(mapping(uint => uint)[] calldata) pure external {} +} +// ---- +// TypeError: (29-52): Type is required to live outside storage. +// TypeError: (29-52): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol new file mode 100644 index 00000000..adcfee2a --- /dev/null +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol @@ -0,0 +1,6 @@ +contract c { + function f1(mapping(uint => uint) calldata) pure external returns (mapping(uint => uint) memory) {} +} +// ---- +// TypeError: (29-50): Type is required to live outside storage. +// TypeError: (29-50): Internal or recursive type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_internal.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_internal.sol new file mode 100644 index 00000000..17f2f712 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_internal.sol @@ -0,0 +1,4 @@ +contract c { + function f4(mapping(uint => uint) memory) pure internal {} +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol new file mode 100644 index 00000000..e98c1fe8 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol @@ -0,0 +1,6 @@ +contract c { + function f3(mapping(uint => uint) memory) view public {} +} +// ---- +// TypeError: (29-50): Type is required to live outside storage. +// TypeError: (29-50): Internal or recursive type is not allowed for public or external functions. -- cgit v1.2.3