diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index b1569fa76..c362375b5 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -989,11 +989,16 @@ ASTPointer Parser::parseUsingDirective() Token::BitNot }; if (!util::contains(overridable, operator_)) + { parserError( 4403_error, - ("The operator " + string{TokenTraits::toString(operator_)} + " cannot be user-implemented. This is only possible for the following operators: ") + + ( + "The operator " + (TokenTraits::toString(operator_) ? string(TokenTraits::toString(operator_)) + " " : "") + + "cannot be user-implemented. This is only possible for the following operators: " + ) + util::joinHumanReadable(overridable | ranges::views::transform([](Token _t) { return string{TokenTraits::toString(_t)}; })) ); + } operators.emplace_back(operator_); advance(); } diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_error.sol b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_error.sol new file mode 100644 index 000000000..005db60e5 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_error.sol @@ -0,0 +1,10 @@ +using {add as +} for E; + +error E(); + +function add(E, E) pure returns (E) { + return E.E1; +} + +// ---- +// TypeError 5172: (21-22): Name has to refer to a user-defined value type, struct, enum or contract. diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_not_user_implementable.sol b/test/libsolidity/syntaxTests/operators/custom/operator_not_user_implementable.sol index 499b3c5af..94e54ba2a 100644 --- a/test/libsolidity/syntaxTests/operators/custom/operator_not_user_implementable.sol +++ b/test/libsolidity/syntaxTests/operators/custom/operator_not_user_implementable.sol @@ -1,10 +1,14 @@ using { - shiftL as <<, shiftR as >>, - exp as **, neg as ! + shiftL as <<, + shiftR as >>, + exp as **, + neg as !, + f as x } for int256; // ---- // ParserError 4403: (22-24): The operator << cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ -// ParserError 4403: (36-38): The operator >> cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ -// ParserError 4403: (51-53): The operator ** cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ -// ParserError 4403: (62-63): The operator ! cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (40-42): The operator >> cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (55-57): The operator ** cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (70-71): The operator ! cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (82-83): The operator cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_parameter_with_wrong_data_location.sol b/test/libsolidity/syntaxTests/operators/custom/operator_parameters_with_different_data_locations.sol similarity index 100% rename from test/libsolidity/syntaxTests/operators/custom/operator_parameter_with_wrong_data_location.sol rename to test/libsolidity/syntaxTests/operators/custom/operator_parameters_with_different_data_locations.sol diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_with_calldata_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/operator_with_calldata_parameters.sol new file mode 100644 index 000000000..081291ece --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_with_calldata_parameters.sol @@ -0,0 +1,11 @@ +using {add as +} for S; + +struct S { + uint x; +} + +function add(S calldata, S calldata) pure returns (S calldata r) { + assembly { + r := 0 + } +} diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_with_storage_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/operator_with_storage_parameters.sol new file mode 100644 index 000000000..d905104c8 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_with_storage_parameters.sol @@ -0,0 +1,18 @@ +using {add as +} for S; + +struct S { + uint x; +} + +function add(S storage a, S storage) pure returns (S storage) { + return a; +} + +contract C { + S a; + S b; + + function test() public view { + a + b; + } +}