Updates after code review

This commit is contained in:
wechman
2022-09-28 13:09:16 +02:00
parent 7b81a65bc6
commit cdbc06419f
25 changed files with 254 additions and 31 deletions
@@ -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
@@ -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
@@ -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