From 1218b207ef6c2c9403bd0d9deccc7e281edcf538 Mon Sep 17 00:00:00 2001 From: wechman Date: Mon, 8 Aug 2022 14:13:31 +0200 Subject: [PATCH] Add test cases for user type operators with global using for directive --- .../operator_binding_is_not_transitive.sol | 30 +++++++++++++++++++ ...e_user_type_operator_defined_as_global.sol | 24 +++++++++++++++ .../user_type_operator_defined_as_global.sol | 15 ++++++++++ 3 files changed, 69 insertions(+) create mode 100644 test/libsolidity/syntaxTests/operators/custom/operator_binding_is_not_transitive.sol create mode 100644 test/libsolidity/syntaxTests/using/override_user_type_operator_defined_as_global.sol create mode 100644 test/libsolidity/syntaxTests/using/user_type_operator_defined_as_global.sol 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.sol new file mode 100644 index 000000000..429c53509 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operator_binding_is_not_transitive.sol @@ -0,0 +1,30 @@ +==== Source: s0.sol ==== +type Int is int; + +==== Source: s1.sol ==== +import "s0.sol"; +using {add1 as +} for Int; + +function add1(Int, Int) returns (Int) { + return Int.wrap(3); +} + +==== Source: s2.sol ==== +import "s0.sol"; +using {add2 as +} for Int; + +function add2(Int, Int) returns (Int) { + return Int.wrap(7); +} + +==== Source: s3.sol ==== +import "s1.sol"; +import "s2.sol"; +contract C { + function f() public { + Int.wrap(0) + Int.wrap(0); + } +} + +// ---- +// TypeError 2271: (s3.sol:81-106): Operator + not compatible with types Int and Int. No matching user-defined operator found. diff --git a/test/libsolidity/syntaxTests/using/override_user_type_operator_defined_as_global.sol b/test/libsolidity/syntaxTests/using/override_user_type_operator_defined_as_global.sol new file mode 100644 index 000000000..1078ce5da --- /dev/null +++ b/test/libsolidity/syntaxTests/using/override_user_type_operator_defined_as_global.sol @@ -0,0 +1,24 @@ +==== Source: s1.sol ==== +type Int is int; +using {add as +} for Int global; + +function add(Int, Int) pure returns (Int) { + return Int.wrap(3); +} + +==== Source: s2.sol ==== +import "s1.sol"; + +using {another_add as +} for Int; + +function another_add(Int, Int) pure returns (Int) { + return Int.wrap(3); +} + +contract C { + function f() pure public { + Int.wrap(0) + Int.wrap(0); + } +} +// ---- +// TypeError 2271: (s2.sol:184-209): Operator + not compatible with types Int and 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 new file mode 100644 index 000000000..cba78f561 --- /dev/null +++ b/test/libsolidity/syntaxTests/using/user_type_operator_defined_as_global.sol @@ -0,0 +1,15 @@ +==== Source: s1.sol ==== +type Int is int; +using {add as +} for Int global; + +function add(Int, Int) pure returns (Int) { + return Int.wrap(3); +} + +==== Source: s2.sol ==== +import "s1.sol"; +contract C { + function f() pure public { + Int.wrap(0) + Int.wrap(0); + } +}