Skip to content

Commit

Permalink
New tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Oct 19, 2020
1 parent b53b952 commit 37fc84b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
contract C {
function add(uint16 a, uint16 b) public returns (uint16) {
return a + b;
}

function f(uint16 a, uint16 b, uint16 c) public returns (uint16) {
unchecked { return add(a, b) + c; }
}
}
// ====
// compileViaYul: also
// ----
// f(uint16,uint16,uint16): 0xe000, 0xe500, 2 -> FAILURE
// f(uint16,uint16,uint16): 0xe000, 0x1000, 0x1000 -> 0x00
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contract C {
modifier add(uint16 a, uint16 b) {
unchecked { a + b; }
_;
}

function f(uint16 a, uint16 b, uint16 c) public add(a, b) returns (uint16) {
return b + c;
}
}
// ====
// compileViaYul: also
// ----
// f(uint16,uint16,uint16): 0xe000, 0xe500, 2 -> 58626
// f(uint16,uint16,uint16): 0x1000, 0xe500, 0xe000 -> FAILURE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
contract C {
function add(uint16 a, uint16 b) public returns (uint16) {
unchecked {
return a + b;
}
}

function f(uint16 a) public returns (uint16) {
return add(a, 0x100) + 0x100;
}
}
// ====
// compileViaYul: also
// ----
// f(uint16): 7 -> 0x0207
// f(uint16): 0xffff -> 511
// f(uint16): 0xfeff -> FAILURE
8 changes: 8 additions & 0 deletions test/libsolidity/syntaxTests/unchecked/unchecked_vardecl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract C {
uint x = unchecked { f() + 2 }
function f() public pure returns (uint) {
return 4;
}
}
// ----
// ParserError 6933: (26-35): Expected primary expression.

0 comments on commit 37fc84b

Please sign in to comment.