Merge pull request #10445 from ethereum/modifiers

[Sol->Yul] Implement function modifiers.
This commit is contained in:
chriseth
2020-12-18 14:29:00 +01:00
committed by GitHub
36 changed files with 345 additions and 21 deletions
@@ -34,5 +34,7 @@ contract C is B {
return (x, y);
}
}
// ====
// compileViaYul: also
// ----
// test() -> 5, 10
@@ -8,6 +8,8 @@ contract C {
return b + c;
}
}
// ====
// compileViaYul: also
// ----
// f(uint16,uint16,uint16): 0xe000, 0xe500, 2 -> 58626
// f(uint16,uint16,uint16): 0x1000, 0xe500, 0xe000 -> FAILURE, hex"4e487b71", 0x11
@@ -28,6 +28,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> true
// g() -> FAILURE
@@ -14,6 +14,8 @@ contract C {
x = t;
}
}
// ====
// compileViaYul: also
// ----
// x() -> 0
// f() ->
@@ -14,6 +14,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// x() -> 0
// f() ->
@@ -0,0 +1,22 @@
contract A { constructor(uint) {} }
contract B { constructor(uint) {} }
contract C { constructor(uint) {} }
contract D is A, B, C {
uint[] x;
constructor() m2(f(1)) B(f(2)) m1(f(3)) C(f(4)) m3(f(5)) A(f(6)) {
f(7);
}
function query() public view returns (uint[] memory) { return x; }
modifier m1(uint) { _; }
modifier m2(uint) { _; }
modifier m3(uint) { _; }
function f(uint y) internal returns (uint) { x.push(y); return 0; }
}
// ====
// compileViaYul: also
// ----
// query() -> 0x20, 7, 4, 2, 6, 1, 3, 5, 7
@@ -8,6 +8,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// getOne() -> 0
// getOne(), 1 wei -> 1
@@ -45,5 +45,7 @@ contract C is A {
}
}
// ====
// compileViaYul: also
// ----
// getData() -> 0x4300
@@ -13,5 +13,7 @@ contract C is A {
}
}
// ====
// compileViaYul: also
// ----
// f() -> false
@@ -22,6 +22,7 @@ contract C is A {
_;
}
}
// ====
// compileViaYul: also
// ----
// getData() -> 6
@@ -24,5 +24,7 @@ contract Test {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x202
@@ -30,5 +30,7 @@ contract Test {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x202
@@ -14,6 +14,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f(bool): true -> 0
// f(bool): false -> 3
@@ -8,6 +8,7 @@ contract C {
r += 1;
}
}
// ====
// compileViaYul: false
// ----
// f() -> 10
@@ -0,0 +1,14 @@
contract C {
modifier repeat(uint256 count) {
uint256 i;
for (i = 0; i < count; ++i) _;
}
function f() public repeat(10) returns (uint256 r) {
r += 1;
}
}
// ====
// compileViaYul: true
// ----
// f() -> 1
@@ -8,7 +8,8 @@ contract C {
r += 1;
}
}
// ====
// compileViaYul: false
// ----
// f(bool): false -> 1
// f(bool): true -> 2
@@ -0,0 +1,15 @@
contract C {
modifier repeat(bool twice) {
if (twice) _;
_;
}
function f(bool twice) public repeat(twice) returns (uint256 r) {
r += 1;
}
}
// ====
// compileViaYul: true
// ----
// f(bool): false -> 1
// f(bool): true -> 1
@@ -11,7 +11,8 @@ contract C {
return r;
}
}
// ====
// compileViaYul: false
// ----
// f(bool): false -> 1
// f(bool): true -> 2
@@ -10,6 +10,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 3 -> 10
// a() -> 10
@@ -13,6 +13,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 3 -> 10
// a() -> 0
@@ -15,5 +15,7 @@ contract C is A {
}
}
// ====
// compileViaYul: also
// ----
// f() -> false
@@ -0,0 +1,15 @@
contract C {
modifier m(bool condition) {
if (condition) _;
}
function f(uint x) public m(x >= 10) returns (uint[5] memory r) {
r[2] = 3;
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 9 -> 0x00, 0x00, 0x00, 0x00, 0x00
// f(uint256): 10 -> 0x00, 0x00, 3, 0x00, 0x00
@@ -10,6 +10,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// x() -> 0
// f() -> 2
@@ -14,6 +14,8 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// x() -> 0
// f() ->
@@ -15,6 +15,8 @@ contract C {
}
}
}
// ====
// compileViaYul: also
// ----
// x() -> 0
// f() -> 42
@@ -13,6 +13,8 @@ contract C {
return address(this).balance;
}
}
// ====
// compileViaYul: also
// ----
// f(), 27 wei -> FAILURE
// balance() -> 0
@@ -16,6 +16,8 @@ contract C {
x += 3;
}
}
// ====
// compileViaYul: also
// ----
// f1() ->
// x() -> 0x08