aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/syntaxTests/functionTypes
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity/syntaxTests/functionTypes')
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol8
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol17
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol10
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol11
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol11
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol8
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol9
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol8
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol4
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol9
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/private_function_type.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/public_function_type.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol23
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol5
33 files changed, 252 insertions, 0 deletions
diff --git a/test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol
new file mode 100644
index 00000000..87c3b05b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol
@@ -0,0 +1,8 @@
+contract C {
+ function (uint) external returns (uint) x;
+ function f() public {
+ x.value(2)();
+ }
+}
+// ----
+// TypeError: (94-101): Member "value" not found or not visible after argument-dependent lookup in function (uint256) external returns (uint256) - did you forget the "payable" modifier?
diff --git a/test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol
new file mode 100644
index 00000000..ca2a0196
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol
@@ -0,0 +1,6 @@
+contract C {
+ function (uint) external payable returns (uint) x;
+ function f() public {
+ x.value(2)(1);
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol b/test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol
new file mode 100644
index 00000000..2711dae8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ delete this.f;
+ }
+}
+// ----
+// TypeError: (54-60): Expression has to be an lvalue.
diff --git a/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol
new file mode 100644
index 00000000..a6fe6c22
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol
@@ -0,0 +1,17 @@
+contract C {
+ function(uint) external returns (uint) x;
+ function(uint) internal returns (uint) y;
+ function f() public {
+ delete x;
+ var a = y;
+ delete a;
+ delete y;
+ var c = f;
+ delete c;
+ function(uint) internal returns (uint) g;
+ delete g;
+ }
+}
+// ----
+// Warning: (157-162): Use of the "var" keyword is deprecated.
+// Warning: (212-217): Use of the "var" keyword is deprecated.
diff --git a/test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol b/test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol
new file mode 100644
index 00000000..60da19e4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ delete f;
+ }
+}
+// ----
+// TypeError: (54-55): Expression has to be an lvalue.
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol
new file mode 100644
index 00000000..eb4f0693
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol
@@ -0,0 +1,10 @@
+// This is a test that checks that the type of the `bytes` parameter is
+// correctly changed from its own type `bytes calldata` to `bytes memory`
+// when converting to a function type.
+contract C {
+ function f(function(bytes memory) pure external /*g*/) pure public { }
+ function callback(bytes) pure external {}
+ function g() view public {
+ f(this.callback);
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol
new file mode 100644
index 00000000..0a6d1e53
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol
@@ -0,0 +1,11 @@
+contract C {
+ function (uint) external public x;
+
+ function g(uint) public {
+ x = this.g;
+ }
+ function f() public view returns (function(uint) external) {
+ return this.x();
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol
new file mode 100644
index 00000000..8b14d3dc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol
@@ -0,0 +1,5 @@
+contract C {
+ function() external returns (function () internal) x;
+}
+// ----
+// TypeError: (46-67): Internal type cannot be used for external function type.
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol
new file mode 100644
index 00000000..3e264c8c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(function () internal) external x;
+}
+// ----
+// TypeError: (26-47): Internal type cannot be used for external function type.
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol
new file mode 100644
index 00000000..b86425db
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol
@@ -0,0 +1,5 @@
+contract C {
+ function f() public view returns (address) {
+ return address(this.f);
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol
new file mode 100644
index 00000000..f4287223
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public returns (uint) {
+ return uint(this.f);
+ }
+}
+// ----
+// TypeError: (69-81): Explicit type conversion not allowed from "function () external returns (uint256)" to "uint256".
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type.sol b/test/libsolidity/syntaxTests/functionTypes/function_type.sol
new file mode 100644
index 00000000..23d50136
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() pure public {
+ function(uint) returns (uint) x;
+ x;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol
new file mode 100644
index 00000000..ec23d637
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol
@@ -0,0 +1,11 @@
+contract C {
+ function(uint) external returns (uint)[] public x;
+ function(uint) internal returns (uint)[10] y;
+ function f() view public {
+ function(uint) returns (uint)[10] memory a;
+ function(uint) returns (uint)[10] storage b = y;
+ function(uint) external returns (uint)[] memory c;
+ c = new function(uint) external returns (uint)[](200);
+ a; b;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol
new file mode 100644
index 00000000..95ebc179
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol
@@ -0,0 +1,7 @@
+contract C {
+ // Fool parser into parsing a constructor as a function type.
+ constructor() x;
+}
+// ----
+// Warning: (83-99): Modifiers of functions without implementation are ignored.
+// DeclarationError: (97-98): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol
new file mode 100644
index 00000000..b7763d28
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol
@@ -0,0 +1,8 @@
+contract C {
+ // Fool parser into parsing a constructor as a function type.
+ function f() {
+ constructor() x;
+ }
+}
+// ----
+// ParserError: (118-118): Expected token Semicolon got 'Identifier'
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol
new file mode 100644
index 00000000..4eb53227
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(bytes memory) internal public a;
+}
+// ----
+// TypeError: (17-57): Internal or recursive type is not allowed for public state variables.
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol
new file mode 100644
index 00000000..da66ec8a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol
@@ -0,0 +1,7 @@
+contract C {
+ uint x;
+ function f(function(uint) external returns (uint) g) public returns (function(uint) external returns (uint)) {
+ x = 2;
+ return g;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol
new file mode 100644
index 00000000..9cd313c8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol
@@ -0,0 +1,5 @@
+contract C {
+ function f() public pure returns (function(uint) pure external returns (uint) g) {
+ return g;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol
new file mode 100644
index 00000000..f0240472
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol
@@ -0,0 +1,6 @@
+contract test {
+ function fa(bytes memory) public { }
+ function(bytes memory) external internal a = fa;
+}
+// ----
+// TypeError: (106-108): Type function (bytes memory) is not implicitly convertible to expected type function (bytes memory) external.
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol b/test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol
new file mode 100644
index 00000000..36206d63
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol
@@ -0,0 +1,7 @@
+contract C {
+ // This is an error, you should explicitly use
+ // `external public` to fix it - `internal public` does not exist.
+ function(bytes memory) public a;
+}
+// ----
+// TypeError: (139-170): Invalid visibility, can only be "external" or "internal".
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol b/test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol
new file mode 100644
index 00000000..91c2420a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol
@@ -0,0 +1,9 @@
+contract C {
+ function(bytes memory) a1;
+ function(bytes memory) internal b1;
+ function(bytes memory) internal internal b2;
+ function(bytes memory) external c1;
+ function(bytes memory) external internal c2;
+ function(bytes memory) external public c3;
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol
new file mode 100644
index 00000000..fa92d559
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol
@@ -0,0 +1,8 @@
+// It should not be possible to give internal functions
+// as parameters to external functions.
+contract C {
+ function f(function(uint) internal returns (uint) x) public {
+ }
+}
+// ----
+// TypeError: (124-164): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol
new file mode 100644
index 00000000..b37fb285
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol
@@ -0,0 +1,6 @@
+library L {
+ function f(function(uint) internal returns (uint) x) public {
+ }
+}
+// ----
+// TypeError: (27-67): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol
new file mode 100644
index 00000000..7ffa447e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol
@@ -0,0 +1,4 @@
+library L {
+ function f(function(uint) internal returns (uint) /*x*/) pure internal {
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol
new file mode 100644
index 00000000..41fcd0a4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol
@@ -0,0 +1,7 @@
+// It should not be possible to return internal functions from external functions.
+contract C {
+ function f() public returns (function(uint) internal returns (uint) x) {
+ }
+}
+// ----
+// TypeError: (129-169): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol
new file mode 100644
index 00000000..b75a0d43
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public returns (address) {
+ return address(f);
+ }
+}
+// ----
+// TypeError: (72-82): Explicit type conversion not allowed from "function () returns (address)" to "address".
diff --git a/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol
new file mode 100644
index 00000000..a7cb9d92
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol
@@ -0,0 +1,5 @@
+contract C {
+ function (uint) internal payable returns (uint) x;
+}
+// ----
+// TypeError: (17-66): Only external function types can be payable.
diff --git a/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol
new file mode 100644
index 00000000..5c6dc056
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol
@@ -0,0 +1,9 @@
+contract C {
+ function (uint) internal payable returns (uint) x;
+
+ function g() public {
+ x = g;
+ }
+}
+// ----
+// TypeError: (17-66): Only external function types can be payable.
diff --git a/test/libsolidity/syntaxTests/functionTypes/private_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/private_function_type.sol
new file mode 100644
index 00000000..9d4f0a09
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/private_function_type.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ function(uint) private returns (uint) x;
+ }
+}
+// ----
+// TypeError: (47-86): Invalid visibility, can only be "external" or "internal".
diff --git a/test/libsolidity/syntaxTests/functionTypes/public_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/public_function_type.sol
new file mode 100644
index 00000000..756766d3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/public_function_type.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ function(uint) public returns (uint) x;
+ }
+}
+// ----
+// TypeError: (47-85): Invalid visibility, can only be "external" or "internal".
diff --git a/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol b/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol
new file mode 100644
index 00000000..10c6767c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol
@@ -0,0 +1,23 @@
+contract test {
+ function fa(uint) {}
+ function fb(uint) internal {}
+ function fc(uint) internal {}
+ function fd(uint) external {}
+ function fe(uint) external {}
+ function ff(uint) internal {}
+ function fg(uint) internal pure {}
+ function fh(uint) pure internal {}
+
+ function(uint) a = fa;
+ function(uint) internal b = fb; // (explicit internal applies to the function type)
+ function(uint) internal internal c = fc;
+ function(uint) external d = this.fd;
+ function(uint) external internal e = this.fe;
+ function(uint) internal public f = ff;
+ function(uint) internal pure public g = fg;
+ function(uint) pure internal public h = fh;
+}
+// ----
+// TypeError: (545-582): Internal or recursive type is not allowed for public state variables.
+// TypeError: (588-630): Internal or recursive type is not allowed for public state variables.
+// TypeError: (636-678): Internal or recursive type is not allowed for public state variables.
diff --git a/test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol
new file mode 100644
index 00000000..072c7eb7
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(uint a) f;
+}
+// ----
+// Warning: (26-32): Naming function type parameters is deprecated.
diff --git a/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol
new file mode 100644
index 00000000..67a74e54
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(uint) returns (bool ret) f;
+}
+// ----
+// Warning: (41-49): Naming function type return parameters is deprecated.