solidity/test/libsolidity/semanticTests/literalSuffixes/suffix_vs_operator_precedence.sol
2023-05-17 16:55:14 +02:00

33 lines
696 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);
}
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