mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Updates after code review
This commit is contained in:
@@ -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
|
||||
+30
@@ -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
|
||||
+26
@@ -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
|
||||
Reference in New Issue
Block a user