solidity/test/libsolidity/semanticTests/literalSuffixes/suffix_vs_operator_precedence.sol
2023-03-22 13:16:31 +01:00

37 lines
785 B
Solidity

type Int is int;
using {sub as -, unsub as -} for Int global;
function sub(Int a, Int b) pure returns (Int) {
return Int.wrap((Int.unwrap(a) - Int.unwrap(b)) * 100);
}
function unsub(Int a) pure returns (Int) {
return Int.wrap(Int.unwrap(a) + 10);
}
function u(int x) pure suffix returns (Int) {
return Int.wrap(x + 1);
}
function u(Int x) pure suffix returns (Int) {
return Int.wrap(Int.unwrap(x) + 1);
}
contract C {
function testUnary() public pure returns (Int) {
return -2 u;
}
function testUnaryWithParens() public pure returns (Int) {
return -(2 u);
}
function testBinary() public pure returns (Int) {
return 4 u - 2 u;
}
}
// ----
// testUnary() -> 13
// testUnaryWithParens() -> 13
// testBinary() -> 200