Tests for checked/unchecked suffixes

This commit is contained in:
Kamil Śliwak 2023-03-22 11:36:14 +01:00
parent 79342f45e7
commit 1b867a3edf
3 changed files with 39 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -8,7 +8,7 @@ function uncheckedAdd(U8 x, U8 y) pure returns (U8) {
using {uncheckedAdd as +} for U8 global;
contract D {
contract C {
function testUncheckedOperator() public pure returns (U8) {
return U8.wrap(250) + U8.wrap(10);
}
@ -19,7 +19,6 @@ contract D {
}
}
}
// ----
// testUncheckedOperator() -> 4
// testUncheckedOperatorInUncheckedBlock() -> 4