mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Tests for checked/unchecked suffixes
This commit is contained in:
parent
79342f45e7
commit
1b867a3edf
@ -0,0 +1,18 @@
|
|||||||
|
function checkedSuffix(uint8 x) pure suffix returns (uint8) {
|
||||||
|
return x + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testCheckedSuffix() public pure returns (uint8) {
|
||||||
|
return 250 checkedSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCheckedSuffixInUncheckedBlock() public pure returns (uint8) {
|
||||||
|
unchecked {
|
||||||
|
return 250 checkedSuffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testCheckedSuffix() -> FAILURE, hex"4e487b71", 0x11
|
||||||
|
// testCheckedSuffixInUncheckedBlock() -> FAILURE, hex"4e487b71", 0x11
|
@ -0,0 +1,20 @@
|
|||||||
|
function uncheckedSuffix(uint8 x) pure suffix returns (uint8) {
|
||||||
|
unchecked {
|
||||||
|
return x + 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testUncheckedSuffix() public pure returns (uint8) {
|
||||||
|
return 250 uncheckedSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testUncheckedSuffixInUncheckedBlock() public pure returns (uint8) {
|
||||||
|
unchecked {
|
||||||
|
return 250 uncheckedSuffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testUncheckedSuffix() -> 4
|
||||||
|
// testUncheckedSuffixInUncheckedBlock() -> 4
|
@ -8,7 +8,7 @@ function uncheckedAdd(U8 x, U8 y) pure returns (U8) {
|
|||||||
|
|
||||||
using {uncheckedAdd as +} for U8 global;
|
using {uncheckedAdd as +} for U8 global;
|
||||||
|
|
||||||
contract D {
|
contract C {
|
||||||
function testUncheckedOperator() public pure returns (U8) {
|
function testUncheckedOperator() public pure returns (U8) {
|
||||||
return U8.wrap(250) + U8.wrap(10);
|
return U8.wrap(250) + U8.wrap(10);
|
||||||
}
|
}
|
||||||
@ -19,7 +19,6 @@ contract D {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// testUncheckedOperator() -> 4
|
// testUncheckedOperator() -> 4
|
||||||
// testUncheckedOperatorInUncheckedBlock() -> 4
|
// testUncheckedOperatorInUncheckedBlock() -> 4
|
||||||
|
Loading…
Reference in New Issue
Block a user