From cdbc06419ff331e78d197f0a829cc82ede5cbfdf Mon Sep 17 00:00:00 2001 From: wechman Date: Fri, 16 Sep 2022 12:35:27 +0200 Subject: [PATCH] Updates after code review --- libsolidity/analysis/TypeChecker.cpp | 2 +- .../bind_function_that_shadows_keccak.sol | 16 +++++++ ...d_to_operator_as_global_and_non_global.sol | 30 +++++++++++++ ...obal_binary_operators_in_the_same_file.sol | 26 ++++++++++++ .../binary_operator_cannot_be_applied.sol | 0 .../operators/custom/bind_error.sol | 8 ++++ .../operators/custom/bind_event.sol | 8 ++-- .../bind_function_that_shadows_keccak.sol | 10 +++++ ...t_already_has_function_bound_as_global.sol | 24 +++++++++++ .../operators/custom/bind_to_error.sol | 12 ------ ... => call_operator_as_a_bound_function.sol} | 0 ...sion_between_data_locations_is_blocked.sol | 42 +++++++++++++++++++ .../custom/implicit_conversion_is_blocked.sol | 16 +++---- ...erator_bind_on_file_and_contract_level.sol | 8 +++- ...ing_is_not_transitive_through_imports.sol} | 0 .../custom/operator_bound_to_enum.sol | 2 +- .../custom/operator_bound_to_event.sol | 10 +++++ .../operator_with_calldata_parameters.sol | 6 +-- ...ter_types_different_from_return_types.sol} | 0 .../operator_with_storage_parameters.sol | 6 +-- .../unary_operator_cannot_be_applied.sol | 0 ...o_operator_in_contract_scope_as_global.sol | 16 +++++++ ...nary_operator_as_global_and_non_global.sol | 20 +++++++++ ...nary_operator_as_global_and_non_global.sol | 15 +++++++ .../user_type_operator_defined_as_global.sol | 8 ++++ 25 files changed, 254 insertions(+), 31 deletions(-) create mode 100644 test/libsolidity/semanticTests/operators/custom/bind_function_that_shadows_keccak.sol create mode 100644 test/libsolidity/semanticTests/operators/custom/function_bound_to_operator_as_global_and_non_global.sol create mode 100644 test/libsolidity/semanticTests/operators/custom/global_unary_and_non_global_binary_operators_in_the_same_file.sol rename test/libsolidity/syntaxTests/operators/{custom => }/binary_operator_cannot_be_applied.sol (100%) create mode 100644 test/libsolidity/syntaxTests/operators/custom/bind_error.sol create mode 100644 test/libsolidity/syntaxTests/operators/custom/bind_function_that_shadows_keccak.sol create mode 100644 test/libsolidity/syntaxTests/operators/custom/bind_function_to_operator_that_already_has_function_bound_as_global.sol delete mode 100644 test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol rename test/libsolidity/syntaxTests/operators/custom/{call_operator_by_member_function.sol => call_operator_as_a_bound_function.sol} (100%) create mode 100644 test/libsolidity/syntaxTests/operators/custom/conversion_between_data_locations_is_blocked.sol rename test/libsolidity/syntaxTests/operators/custom/{operator_binding_is_not_transitive.sol => operator_binding_is_not_transitive_through_imports.sol} (100%) create mode 100644 test/libsolidity/syntaxTests/operators/custom/operator_bound_to_event.sol rename test/libsolidity/syntaxTests/operators/custom/{operator_with_different_param_return_types.sol => operator_with_different_parameter_types_different_from_return_types.sol} (100%) rename test/libsolidity/syntaxTests/operators/{custom => }/unary_operator_cannot_be_applied.sol (100%) create mode 100644 test/libsolidity/syntaxTests/using/function_bound_to_operator_in_contract_scope_as_global.sol create mode 100644 test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_binary_operator_as_global_and_non_global.sol create mode 100644 test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_unary_operator_as_global_and_non_global.sol diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 7499dc901..54b83d3a1 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -3874,7 +3874,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) m_errorReporter.typeError( 9921_error, _usingFor.location(), - "The \"using\" directive cannot be used to bind functions to enum types." + "The \"using\" directive cannot be used to bind function to enum type as an operator." ); Type const* normalizedType = TypeProvider::withLocationIfReference( diff --git a/test/libsolidity/semanticTests/operators/custom/bind_function_that_shadows_keccak.sol b/test/libsolidity/semanticTests/operators/custom/bind_function_that_shadows_keccak.sol new file mode 100644 index 000000000..33ac7a501 --- /dev/null +++ b/test/libsolidity/semanticTests/operators/custom/bind_function_that_shadows_keccak.sol @@ -0,0 +1,16 @@ +type Int is int16; + +using {keccak256 as +} for Int; + +function keccak256(Int a, Int b) pure returns (Int) { + return Int.wrap(Int.unwrap(a) + Int.unwrap(b)); +} + +contract C { + function test() public returns (Int) { + return Int.wrap(3) + Int.wrap(4); + } +} + +// ---- +// test() -> 7 diff --git a/test/libsolidity/semanticTests/operators/custom/function_bound_to_operator_as_global_and_non_global.sol b/test/libsolidity/semanticTests/operators/custom/function_bound_to_operator_as_global_and_non_global.sol new file mode 100644 index 000000000..14b868cf6 --- /dev/null +++ b/test/libsolidity/semanticTests/operators/custom/function_bound_to_operator_as_global_and_non_global.sol @@ -0,0 +1,30 @@ +==== Source: s1.sol ==== +type Int is int; + +using {add as +} for Int global; +using {add as +} for Int; + +function add(Int a, Int b) pure returns (Int) { + return Int.wrap(Int.unwrap(a) + Int.unwrap(b)); +} + +function test_add() pure returns (Int) { + return Int.wrap(1) + Int.wrap(2); +} + +==== Source: s2.sol ==== +import "s1.sol"; + +contract C2 { + function test1() pure public returns (Int) { + return test_add(); + } + + function test2() pure public returns (Int) { + return Int.wrap(3) + Int.wrap(4); + } +} + +// ---- +// test1() -> 3 +// test2() -> 7 diff --git a/test/libsolidity/semanticTests/operators/custom/global_unary_and_non_global_binary_operators_in_the_same_file.sol b/test/libsolidity/semanticTests/operators/custom/global_unary_and_non_global_binary_operators_in_the_same_file.sol new file mode 100644 index 000000000..889383ee0 --- /dev/null +++ b/test/libsolidity/semanticTests/operators/custom/global_unary_and_non_global_binary_operators_in_the_same_file.sol @@ -0,0 +1,26 @@ +type Int is int16; + +using {unsub as -} for Int global; +using {sub as -} for Int; + +function sub(Int a, Int b) pure returns (Int) { + return Int.wrap(Int.unwrap(a) - Int.unwrap(b)); +} + +function unsub(Int a) pure returns (Int) { + return Int.wrap(-Int.unwrap(a)); +} + +contract C { + function test_sub() public returns (Int) { + return Int.wrap(7) - Int.wrap(2); + } + + function test_unsub() public returns (Int) { + return -Int.wrap(4); + } +} + +// ---- +// test_sub() -> 5 +// test_unsub() -> -4 diff --git a/test/libsolidity/syntaxTests/operators/custom/binary_operator_cannot_be_applied.sol b/test/libsolidity/syntaxTests/operators/binary_operator_cannot_be_applied.sol similarity index 100% rename from test/libsolidity/syntaxTests/operators/custom/binary_operator_cannot_be_applied.sol rename to test/libsolidity/syntaxTests/operators/binary_operator_cannot_be_applied.sol diff --git a/test/libsolidity/syntaxTests/operators/custom/bind_error.sol b/test/libsolidity/syntaxTests/operators/custom/bind_error.sol new file mode 100644 index 000000000..14a289053 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/bind_error.sol @@ -0,0 +1,8 @@ +type Int is int16; + +using {IntError as +} for Int; + +error IntError(Int a, Int b); + +// ---- +// TypeError 8187: (27-35): Expected function name. diff --git a/test/libsolidity/syntaxTests/operators/custom/bind_event.sol b/test/libsolidity/syntaxTests/operators/custom/bind_event.sol index 14a289053..8f4b636b0 100644 --- a/test/libsolidity/syntaxTests/operators/custom/bind_event.sol +++ b/test/libsolidity/syntaxTests/operators/custom/bind_event.sol @@ -1,8 +1,10 @@ type Int is int16; -using {IntError as +} for Int; +using {C.IntEvent as +} for Int; -error IntError(Int a, Int b); +contract C { + event IntEvent(Int a, Int b); +} // ---- -// TypeError 8187: (27-35): Expected function name. +// TypeError 8187: (27-37): Expected function name. diff --git a/test/libsolidity/syntaxTests/operators/custom/bind_function_that_shadows_keccak.sol b/test/libsolidity/syntaxTests/operators/custom/bind_function_that_shadows_keccak.sol new file mode 100644 index 000000000..1958a8aff --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/bind_function_that_shadows_keccak.sol @@ -0,0 +1,10 @@ +type Int is int16; + +using {keccak256 as +} for Int; + +function keccak256(Int, Int) pure returns (Int) { + return Int.wrap(0); +} + +// ---- +// Warning 2319: (53-128): This declaration shadows a builtin symbol. diff --git a/test/libsolidity/syntaxTests/operators/custom/bind_function_to_operator_that_already_has_function_bound_as_global.sol b/test/libsolidity/syntaxTests/operators/custom/bind_function_to_operator_that_already_has_function_bound_as_global.sol new file mode 100644 index 000000000..68ab09637 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/bind_function_to_operator_that_already_has_function_bound_as_global.sol @@ -0,0 +1,24 @@ +==== Source: Int.sol ==== +type Int is int; + +using {add as +} for Int global; + +function add(Int, Int) pure returns (Int) { + return Int.wrap(0); +} + +==== Source: test.sol ==== +import "Int.sol"; + +using {another_add as +} for Int; + +function another_add(Int, Int) pure returns (Int) { + return Int.wrap(1); +} + +function test() pure returns (Int) { + return Int.wrap(0) + Int.wrap(0); +} + +// ---- +// TypeError 2271: (test.sol:181-206): Binary operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator. diff --git a/test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol b/test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol deleted file mode 100644 index 54a5123ff..000000000 --- a/test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol +++ /dev/null @@ -1,12 +0,0 @@ -type Int is int16; - -using {f as +} for IntError; - -error IntError(); - -function f(Int _a, Int _b) pure returns (Int) { - return Int.wrap(0); -} - -// ---- -// TypeError 5172: (39-47): Name has to refer to a user-defined value type, struct, enum or contract. diff --git a/test/libsolidity/syntaxTests/operators/custom/call_operator_by_member_function.sol b/test/libsolidity/syntaxTests/operators/custom/call_operator_as_a_bound_function.sol similarity index 100% rename from test/libsolidity/syntaxTests/operators/custom/call_operator_by_member_function.sol rename to test/libsolidity/syntaxTests/operators/custom/call_operator_as_a_bound_function.sol diff --git a/test/libsolidity/syntaxTests/operators/custom/conversion_between_data_locations_is_blocked.sol b/test/libsolidity/syntaxTests/operators/custom/conversion_between_data_locations_is_blocked.sol new file mode 100644 index 000000000..3c766a616 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/conversion_between_data_locations_is_blocked.sol @@ -0,0 +1,42 @@ +struct S { + uint8 a; +} + +using {add as +, + sub as -, + mul as *} for S; + +function add(S memory a, S memory) pure returns (S memory) { + return a; +} + +function sub(S calldata a, S calldata) pure returns (S calldata) { + return a; +} + +function mul(S storage a, S storage) pure returns (S storage) { + return a; +} + +contract C { + S s; + function test(S calldata c) public { + S memory m; + + c + c; // calldata to memory + s + s; // storage to memory + + m - m; // memory to calldata + s - s; // storage to calldata + + c * c; // calldata to storage + m * m; // memory to storage + } +} +// ---- +// TypeError 2271: (421-426): Binary operator + not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found. +// TypeError 2271: (458-463): Binary operator + not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found. +// TypeError 2271: (495-500): Binary operator - not compatible with types struct S memory and struct S memory. No matching user-defined operator found. +// TypeError 2271: (532-537): Binary operator - not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found. +// TypeError 2271: (571-576): Binary operator * not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found. +// TypeError 2271: (609-614): Binary operator * not compatible with types struct S memory and struct S memory. No matching user-defined operator found. diff --git a/test/libsolidity/syntaxTests/operators/custom/implicit_conversion_is_blocked.sol b/test/libsolidity/syntaxTests/operators/custom/implicit_conversion_is_blocked.sol index 37fabb068..a7a4c8181 100644 --- a/test/libsolidity/syntaxTests/operators/custom/implicit_conversion_is_blocked.sol +++ b/test/libsolidity/syntaxTests/operators/custom/implicit_conversion_is_blocked.sol @@ -16,9 +16,10 @@ contract C { S s; function test() public { - S memory sTmp; + S storage sTmp; + S memory tmp; s + s; - sTmp + true; + tmp + true; true + s; -sTmp; -s; @@ -27,8 +28,9 @@ contract C { } // ---- -// TypeError 2271: (288-293): Binary operator + not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found. -// TypeError 5653: (303-314): User defined binary operator + not compatible with types struct S memory and bool. -// TypeError 2271: (324-332): Binary operator + not compatible with types bool and struct S storage ref. -// TypeError 4907: (357-359): Unary operator - cannot be applied to type struct S storage ref. No matching user-defined operator found. -// TypeError 4907: (369-374): Unary operator - cannot be applied to type bool. +// TypeError 2271: (311-316): Binary operator + not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found. +// TypeError 5653: (326-336): User defined binary operator + not compatible with types struct S memory and bool. +// TypeError 2271: (346-354): Binary operator + not compatible with types bool and struct S storage ref. +// TypeError 4907: (364-369): Unary operator - cannot be applied to type struct S storage pointer. No matching user-defined operator found. +// TypeError 4907: (379-381): Unary operator - cannot be applied to type struct S storage ref. No matching user-defined operator found. +// TypeError 4907: (391-396): Unary operator - cannot be applied to type bool. 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 index 54999efb4..234122cde 100644 --- 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 @@ -10,7 +10,7 @@ function another_add(Int, Int) pure returns (Int) { return Int.wrap(0); } -contract C { +contract B { using {another_add as +} for Int; function f() public { @@ -18,5 +18,11 @@ contract C { } } +contract C is B { + function g() public { + Int.wrap(0) + Int.wrap(0); + } +} + // ---- // TypeError 2271: (281-306): Binary 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_binding_is_not_transitive.sol b/test/libsolidity/syntaxTests/operators/custom/operator_binding_is_not_transitive_through_imports.sol similarity index 100% rename from test/libsolidity/syntaxTests/operators/custom/operator_binding_is_not_transitive.sol rename to test/libsolidity/syntaxTests/operators/custom/operator_binding_is_not_transitive_through_imports.sol diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_enum.sol b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_enum.sol index 3a1520da5..ca0b34854 100644 --- a/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_enum.sol +++ b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_enum.sol @@ -10,4 +10,4 @@ function add(E, E) pure returns (E) { } // ---- -// TypeError 9921: (0-23): The "using" directive cannot be used to bind functions to enum types. +// TypeError 9921: (0-23): The "using" directive cannot be used to bind function to enum type as an operator. diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_event.sol b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_event.sol new file mode 100644 index 000000000..367bf1826 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_bound_to_event.sol @@ -0,0 +1,10 @@ +using {add as +} for C.Event; + +contract C { + event Event(); +} + +function add(C.Event, C.Event) pure returns (C.Event) {} + +// ---- +// TypeError 5172: (21-28): Name has to refer to a user-defined value type, struct, enum or contract. diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_with_calldata_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/operator_with_calldata_parameters.sol index 01c7055e5..d8b14130c 100644 --- a/test/libsolidity/syntaxTests/operators/custom/operator_with_calldata_parameters.sol +++ b/test/libsolidity/syntaxTests/operators/custom/operator_with_calldata_parameters.sol @@ -47,7 +47,7 @@ function bitnot(S calldata) pure { } function test(S calldata s) pure { - s + s; + s + s; // OK s - s; s * s; s / s; @@ -64,5 +64,5 @@ function test(S calldata s) pure { // TypeError 7617: (82-87): The function "unsub" needs to have one or two parameters of type S and the same data location to be used for the operator -. // TypeError 3605: (82-87): The function "unsub" needs to have parameters and return value of the same type to be used for the operator -. // TypeError 7743: (98-104): The function "bitnot" needs to return exactly one value of type S to be used for the operator ~. -// TypeError 2271: (758-763): Binary operator * not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found. -// TypeError 4907: (791-793): Unary operator - cannot be applied to type struct S calldata. No matching user-defined operator found. +// TypeError 2271: (764-769): Binary operator * not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found. +// TypeError 4907: (797-799): Unary operator - cannot be applied to type struct S calldata. No matching user-defined operator found. diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_with_different_param_return_types.sol b/test/libsolidity/syntaxTests/operators/custom/operator_with_different_parameter_types_different_from_return_types.sol similarity index 100% rename from test/libsolidity/syntaxTests/operators/custom/operator_with_different_param_return_types.sol rename to test/libsolidity/syntaxTests/operators/custom/operator_with_different_parameter_types_different_from_return_types.sol diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_with_storage_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/operator_with_storage_parameters.sol index 89c3643e0..47c5312bc 100644 --- a/test/libsolidity/syntaxTests/operators/custom/operator_with_storage_parameters.sol +++ b/test/libsolidity/syntaxTests/operators/custom/operator_with_storage_parameters.sol @@ -43,7 +43,7 @@ contract C { S b; function test() public view { - a + b; + a + b; // OK a - b; a * b; a / b; @@ -59,5 +59,5 @@ contract C { // TypeError 7743: (68-71): The function "mod" needs to return exactly one value of type S to be used for the operator %. // TypeError 7743: (82-87): The function "unsub" needs to return exactly one value of type S to be used for the operator -. // TypeError 1147: (98-104): The function "bitnot" needs to have exactly one parameter of type S to be used for the operator ~. -// TypeError 2271: (722-727): Binary operator * not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found. -// TypeError 4907: (779-781): Unary operator ~ cannot be applied to type struct S storage ref. No matching user-defined operator found. +// TypeError 2271: (728-733): Binary operator * not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found. +// TypeError 4907: (785-787): Unary operator ~ cannot be applied to type struct S storage ref. No matching user-defined operator found. diff --git a/test/libsolidity/syntaxTests/operators/custom/unary_operator_cannot_be_applied.sol b/test/libsolidity/syntaxTests/operators/unary_operator_cannot_be_applied.sol similarity index 100% rename from test/libsolidity/syntaxTests/operators/custom/unary_operator_cannot_be_applied.sol rename to test/libsolidity/syntaxTests/operators/unary_operator_cannot_be_applied.sol diff --git a/test/libsolidity/syntaxTests/using/function_bound_to_operator_in_contract_scope_as_global.sol b/test/libsolidity/syntaxTests/using/function_bound_to_operator_in_contract_scope_as_global.sol new file mode 100644 index 000000000..33174c210 --- /dev/null +++ b/test/libsolidity/syntaxTests/using/function_bound_to_operator_in_contract_scope_as_global.sol @@ -0,0 +1,16 @@ +type Int is int16; + +function add(Int, Int) pure returns (Int) { + return Int.wrap(0); +} + +contract C { + using {add as +} for Int global; + + function test() pure public { + Int.wrap(0) + Int.wrap(0); + } +} + +// ---- +// SyntaxError 3367: (108-140): "global" can only be used at file level. diff --git a/test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_binary_operator_as_global_and_non_global.sol b/test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_binary_operator_as_global_and_non_global.sol new file mode 100644 index 000000000..573cc7f1a --- /dev/null +++ b/test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_binary_operator_as_global_and_non_global.sol @@ -0,0 +1,20 @@ +==== Source: s1.sol ==== +type Int is int; + +using {add as +} for Int global; +using {another_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); +} + +function test() pure returns (Int) { + return Int.wrap(1) + Int.wrap(2); +} + +// ---- +// TypeError 2271: (s1.sol:284-309): Binary operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator. diff --git a/test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_unary_operator_as_global_and_non_global.sol b/test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_unary_operator_as_global_and_non_global.sol new file mode 100644 index 000000000..cc8de2790 --- /dev/null +++ b/test/libsolidity/syntaxTests/using/two_functions_bound_to_the_same_unary_operator_as_global_and_non_global.sol @@ -0,0 +1,15 @@ +type Int is int; + +using {unsub as -} for Int global; +using {another_unsub as -} for Int; + +function unsub(Int) pure returns (Int) {} + +function another_unsub(Int) pure returns (Int) {} + +function test() pure returns (Int) { + return -Int.wrap(2); +} + +// ---- +// TypeError 4907: (232-244): Built-in unary operator - cannot be applied to type Int. Multiple user-defined functions provided for this operator. diff --git a/test/libsolidity/syntaxTests/using/user_type_operator_defined_as_global.sol b/test/libsolidity/syntaxTests/using/user_type_operator_defined_as_global.sol index cba78f561..47513b7d6 100644 --- a/test/libsolidity/syntaxTests/using/user_type_operator_defined_as_global.sol +++ b/test/libsolidity/syntaxTests/using/user_type_operator_defined_as_global.sol @@ -1,15 +1,23 @@ ==== Source: s1.sol ==== type Int is int; using {add as +} for Int global; +using {sub as -} for Int; function add(Int, Int) pure returns (Int) { return Int.wrap(3); } +function sub(Int, Int) pure returns (Int) { + return Int.wrap(4); +} + ==== Source: s2.sol ==== import "s1.sol"; contract C { function f() pure public { Int.wrap(0) + Int.wrap(0); + Int.wrap(0) - Int.wrap(0); } } +// ---- +// TypeError 2271: (s2.sol:104-129): Binary operator - not compatible with types Int and Int. No matching user-defined operator found.