Additional tests for user type operators

This commit is contained in:
wechman 2022-08-09 09:32:19 +02:00
parent f6543f772d
commit 9badef916e
6 changed files with 128 additions and 10 deletions

View File

@ -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

View File

@ -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".

View File

@ -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.

View File

@ -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.

View File

@ -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 ')'

View File

@ -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".