diff --git a/test/libsolidity/semanticTests/operators/custom/redefine_operator_bind_in_derived_contract.sol b/test/libsolidity/semanticTests/operators/custom/redefine_operator_bind_in_derived_contract.sol new file mode 100644 index 000000000..81f08ade6 --- /dev/null +++ b/test/libsolidity/semanticTests/operators/custom/redefine_operator_bind_in_derived_contract.sol @@ -0,0 +1,29 @@ +type Int is int128; + +function add(Int, Int) pure returns (Int) { + return Int.wrap(3); +} + +function another_add(Int, Int) pure returns (Int) { + return Int.wrap(7); +} + +contract B { + using {add as +} for Int; + + function f() pure public returns (Int) { + return Int.wrap(0) + Int.wrap(0); + } +} + +contract C is B { + using {another_add as +} for Int; + + function g() pure public returns (Int) { + return Int.wrap(0) + Int.wrap(0); + } +} + +// ---- +// f() -> 3 +// g() -> 7 diff --git a/test/libsolidity/syntaxTests/operators/custom/binary_operator_bind_function_without_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/binary_operator_bind_function_without_parameters.sol new file mode 100644 index 000000000..918e0ca68 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/binary_operator_bind_function_without_parameters.sol @@ -0,0 +1,12 @@ +type Int is int; + +using { + f as + +} for Int; + +function f() returns (Int) { + return Int.wrap(0); +} + +// ---- +// TypeError 4731: (30-31): The function "f" does not have any parameters, and therefore cannot be bound to the type "Int". diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_bind_is_not_inherited.sol b/test/libsolidity/syntaxTests/operators/custom/operator_bind_is_not_inherited.sol new file mode 100644 index 000000000..d5e56e9c8 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_bind_is_not_inherited.sol @@ -0,0 +1,34 @@ +type Int is int128; + +function add(Int, Int) pure returns (Int) { + return Int.wrap(3); +} + +function another_add(Int, Int) pure returns (Int) { + return Int.wrap(7); +} + +contract B { + using {add as +} for Int; + + function f() pure public returns (Int) { + return Int.wrap(0) + Int.wrap(0); + } +} + +contract C is B { + using {another_add as +} for Int; + + function g() pure public returns (Int) { + return Int.wrap(0) + Int.wrap(0); + } +} + +contract D is B { + function h() pure public returns (Int) { + return Int.wrap(0) + Int.wrap(0); + } +} + +// ---- +// TypeError 2271: (542-567): Operator + not compatible with types Int and Int. No matching user-defined operator found. diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_bind_on_file_and_contract_level.sol b/test/libsolidity/syntaxTests/operators/custom/operator_bind_on_file_and_contract_level.sol new file mode 100644 index 000000000..1d6cc6148 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_bind_on_file_and_contract_level.sol @@ -0,0 +1,22 @@ +type Int is int; + +using {add as +} for Int; + +function add(Int, Int) pure returns (Int) { + return Int.wrap(0); +} + +function another_add(Int, Int) pure returns (Int) { + return Int.wrap(0); +} + +contract C { + using {another_add as +} for Int; + + function f() public { + Int.wrap(0) + Int.wrap(0); + } +} + +// ---- +// TypeError 2271: (281-306): Operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator. 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 94e54ba2a..d84ee8692 100644 --- a/test/libsolidity/syntaxTests/operators/custom/operator_not_user_implementable.sol +++ b/test/libsolidity/syntaxTests/operators/custom/operator_not_user_implementable.sol @@ -1,14 +1,23 @@ using { - shiftL as <<, - shiftR as >>, - exp as **, - neg as !, - f as x + f as <<, + f as >>, + f as **, + f as ++, + f as !, + f as x, + f as delete, + f as new, + f as () } for int256; // ---- -// ParserError 4403: (22-24): 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: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (17-19): The operator << cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (30-32): The operator >> cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (43-45): The operator ** cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (56-58): The operator ++ cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (69-70): The operator ! cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (81-82): The operator cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (93-99): The operator delete cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (110-113): The operator new cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 4403: (124-125): The operator ( cannot be user-implemented. This is only possible for the following operators: |, &, ^, +, -, *, /, %, ==, !=, <, >, <=, >=, ~ +// ParserError 2314: (125-126): Expected '}' but got ')' diff --git a/test/libsolidity/syntaxTests/operators/custom/unary_operator_bind_function_without_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/unary_operator_bind_function_without_parameters.sol new file mode 100644 index 000000000..29cc20372 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/unary_operator_bind_function_without_parameters.sol @@ -0,0 +1,12 @@ +type Int is int; + +using { + f as ~ +} for Int; + +function f() returns (Int) { + return Int.wrap(0); +} + +// ---- +// TypeError 4731: (30-31): The function "f" does not have any parameters, and therefore cannot be bound to the type "Int".