Code generation for errors.

This commit is contained in:
chriseth
2021-03-30 21:15:46 +02:00
parent 3353107779
commit d5669696d5
16 changed files with 236 additions and 40 deletions
@@ -0,0 +1,24 @@
error E(uint a);
library L {
error E(uint a, uint b);
}
interface I {
error E(uint a, uint b, uint c);
}
contract C {
function f() public pure {
revert E(1);
}
function g() public pure {
revert L.E(1, 2);
}
function h() public pure {
revert I.E(1, 2, 3);
}
}
// ====
// compileViaYul: also
// ----
// f() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000001"
// g() -> FAILURE, hex"85208890", hex"0000000000000000000000000000000000000000000000000000000000000001", hex"0000000000000000000000000000000000000000000000000000000000000002"
// h() -> FAILURE, hex"7924ea7c", hex"0000000000000000000000000000000000000000000000000000000000000001", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000003"
@@ -0,0 +1,10 @@
error E(uint a, uint b);
contract C {
function f() public pure {
revert E({b: 7, a: 2});
}
}
// ====
// compileViaYul: also
// ----
// f() -> FAILURE, hex"85208890", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000007"
@@ -0,0 +1,12 @@
error E(string a, uint[] b);
contract C {
uint[] x;
function f() public {
x.push(7);
revert E("abc", x);
}
}
// ====
// compileViaYul: also
// ----
// f() -> FAILURE, hex"59e4d4df", 0x40, 0x80, 3, "abc", 1, 7
@@ -0,0 +1,10 @@
error E(uint a, uint b);
contract C {
function f() public pure {
revert E(2, 7);
}
}
// ====
// compileViaYul: also
// ----
// f() -> FAILURE, hex"85208890", 2, 7
@@ -0,0 +1,18 @@
contract A {
error E(uint);
}
contract X {
error E(string);
}
contract B is A {
function f() public pure { revert E(1); }
function g() public pure { revert A.E(1); }
function h() public pure { revert X.E("abc"); }
}
// ====
// compileViaYul: also
// ----
// f() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000001"
// g() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000001"
// h() -> FAILURE, hex"3e9992c9", hex"0000000000000000000000000000000000000000000000000000000000000020", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"6162630000000000000000000000000000000000000000000000000000000000"
@@ -0,0 +1,25 @@
==== Source: s1.sol ====
error E(uint);
==== Source: s2.sol ====
import "s1.sol" as S;
==== Source: s3.sol ====
import "s1.sol" as S;
import "s2.sol" as T;
import "s1.sol";
contract C {
function x() public pure {
revert E(1);
}
function y() public pure {
revert S.E(2);
}
function z() public pure {
revert T.S.E(3);
}
}
// ====
// compileViaYul: also
// ----
// x() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000001"
// y() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000002"
// z() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000003"
@@ -0,0 +1,10 @@
error error(uint a);
contract C {
function f() public pure {
revert error(2);
}
}
// ====
// compileViaYul: also
// ----
// f() -> FAILURE, hex"b48fb6cf", hex"0000000000000000000000000000000000000000000000000000000000000002"
@@ -0,0 +1,17 @@
struct error { uint error; }
contract C {
error test();
error _struct;
function f() public {
revert test();
}
function g(uint x) public returns (uint) {
_struct.error = x;
return _struct.error;
}
}
// ====
// compileViaYul: also
// ----
// f() -> FAILURE, hex"f8a8fd6d"
// g(uint256): 7 -> 7