mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Revert statement.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
==== Source: s1.sol ====
|
||||
error E(uint);
|
||||
==== Source: s2.sol ====
|
||||
import { E as Panic } from "s1.sol";
|
||||
contract C {
|
||||
error E(uint);
|
||||
function a() public pure {
|
||||
revert Panic(1);
|
||||
}
|
||||
function b() public pure {
|
||||
revert E(1);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// a() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000001"
|
||||
// b() -> FAILURE, hex"002ff067", hex"0000000000000000000000000000000000000000000000000000000000000001"
|
||||
@@ -0,0 +1,20 @@
|
||||
pragma abicoder v2;
|
||||
struct S { uint a; string b; }
|
||||
error E(uint a, S s, uint b);
|
||||
contract C {
|
||||
S s;
|
||||
function f(bool c) public {
|
||||
if (c) {
|
||||
s.a = 9;
|
||||
s.b = "abc";
|
||||
revert E(2, s, 7);
|
||||
} else {
|
||||
revert E({b: 7, a: 2, s: S({b: "abc", a: 9})});
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(bool): true -> FAILURE, hex"e96e07f0", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"0000000000000000000000000000000000000000000000000000000000000007", hex"0000000000000000000000000000000000000000000000000000000000000009", hex"0000000000000000000000000000000000000000000000000000000000000040", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"6162630000000000000000000000000000000000000000000000000000000000"
|
||||
// f(bool): false -> FAILURE, hex"e96e07f0", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"0000000000000000000000000000000000000000000000000000000000000007", hex"0000000000000000000000000000000000000000000000000000000000000009", hex"0000000000000000000000000000000000000000000000000000000000000040", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"6162630000000000000000000000000000000000000000000000000000000000"
|
||||
@@ -0,0 +1,8 @@
|
||||
error E(uint a, uint b);
|
||||
contract C {
|
||||
function f(bool c) public pure {
|
||||
require(c, E(2, 7));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9322: (83-90): No matching declaration found after argument-dependent lookup.
|
||||
@@ -0,0 +1,8 @@
|
||||
error E(uint a, uint b);
|
||||
contract C {
|
||||
function f() public pure {
|
||||
revert(E(2, 7));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9322: (77-83): No matching declaration found after argument-dependent lookup.
|
||||
@@ -0,0 +1,3 @@
|
||||
revert X();
|
||||
// ----
|
||||
// ParserError 2314: (8-9): Expected ';' but got '('
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
E();
|
||||
}
|
||||
// ----
|
||||
// TypeError 7757: (35-38): Errors can only be used with revert statements: "revert MyError();".
|
||||
@@ -0,0 +1,4 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
revert E();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
function f() public pure {
|
||||
revert E;
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (50-51): Expected '(' but got ';'
|
||||
@@ -0,0 +1,5 @@
|
||||
function f() public pure {
|
||||
revert 1;
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (38-39): Expected ';' but got 'Number'
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
contract C {
|
||||
function f() public pure {
|
||||
revert E();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
event E();
|
||||
function f() public pure {
|
||||
revert E();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1885: (74-75): Expression has to be an error.
|
||||
@@ -0,0 +1,8 @@
|
||||
error revert();
|
||||
contract C {
|
||||
function f() public pure {
|
||||
revert revert();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 2319: (0-15): This declaration shadows a builtin symbol.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract A {
|
||||
error E();
|
||||
}
|
||||
contract C {
|
||||
function f() public pure {
|
||||
revert A.E();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
error f(uint, uint);
|
||||
contract C {
|
||||
function f(uint) public {
|
||||
revert f(10);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (38-91): This declaration shadows an existing declaration.
|
||||
// TypeError 1885: (79-80): Expression has to be an error.
|
||||
@@ -0,0 +1,8 @@
|
||||
struct S { uint x; }
|
||||
contract C {
|
||||
function f() public {
|
||||
revert S(10);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1885: (75-76): Expression has to be an error.
|
||||
Reference in New Issue
Block a user