Add user operator test cases

This commit is contained in:
wechman 2022-07-28 08:39:10 +02:00
parent 3be5114fb0
commit 7d12eb5745
7 changed files with 144 additions and 0 deletions

View File

@ -0,0 +1,29 @@
type SmallInt is int;
type BigInt is int;
using {add1 as +} for SmallInt;
using {add2 as +} for BigInt;
function add1(SmallInt, SmallInt) pure returns (SmallInt) {
return SmallInt.wrap(1);
}
function add2(BigInt, BigInt) pure returns (BigInt) {
return BigInt.wrap(2);
}
contract C {
function f() public pure returns (SmallInt) {
return SmallInt.wrap(0) + SmallInt.wrap(0);
}
function g() public pure returns (BigInt) {
return BigInt.wrap(0) + BigInt.wrap(0);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 1
// g() -> 2

View File

@ -0,0 +1,43 @@
type Int is int;
function add1(Int, Int) pure returns (Int) {
return Int.wrap(1);
}
function add2(Int, Int) pure returns (Int) {
return Int.wrap(2);
}
contract C1 {
using {add1 as +} for Int;
function f() public returns (Int) {
return Int.wrap(0) + Int.wrap(0);
}
}
contract C2 {
using {add2 as +} for Int;
function f() public returns (Int) {
return Int.wrap(0) + Int.wrap(0);
}
}
contract C {
function test1() public returns (Int) {
C1 c = new C1();
return c.f();
}
function test2() public returns (Int) {
C2 c = new C2();
return c.f();
}
}
// ====
// compileViaYul: also
// ----
// test1() -> 1
// test2() -> 2

View File

@ -0,0 +1,28 @@
==== Source: a.sol ====
pragma abicoder v2;
library L {
type Int is int128;
function add(Int, Int) pure public returns (Int) {
return Int.wrap(7);
}
}
==== Source: b.sol ====
pragma abicoder v2;
import "a.sol" as a;
==== Source: c.sol ====
pragma abicoder v2;
import "b.sol" as b;
contract C {
using {b.a.L.add as +} for b.a.L.Int;
function f() pure public returns (b.a.L.Int) {
return b.a.L.Int.wrap(0) + b.a.L.Int.wrap(0);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 7

View File

@ -0,0 +1,12 @@
type Int is int;
function add(Int, Int) returns (Int) {
return Int.wrap(0);
}
contract C {
using {add as +} for *;
}
// ----
// SyntaxError 3349: (101-124): The type has to be specified explicitly when attaching specific functions.

View File

@ -0,0 +1,12 @@
type Int is int;
contract C {
using {add as +} for Int;
function add(Int, Int) public returns (Int) {
return 0;
}
}
// ----
// TypeError 4167: (42-45): Only file-level functions and library functions can be bound to a type in a "using" statement

View File

@ -0,0 +1,8 @@
using {add as +} for *;
function add(int, int) returns (int) {
return 0;
}
// ----
// SyntaxError 8118: (0-23): The type has to be specified explicitly at file level (cannot use '*').

View File

@ -0,0 +1,12 @@
type Int is int;
using {C.add as +} for Int;
contract C {
function add(Int, Int) public returns (Int) {
return 0;
}
}
// ----
// TypeError 4167: (25-30): Only file-level functions and library functions can be bound to a type in a "using" statement