mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Syntax for custom errors.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
error MyError();
|
||||
error MyError2(uint x);
|
||||
error MyError3(uint x, bytes);
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,9 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
revert(E());
|
||||
}
|
||||
function g() pure {
|
||||
bool x;
|
||||
require(x, E());
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,9 @@
|
||||
error E(uint,string);
|
||||
function f() pure {
|
||||
revert(E(2, "abc"));
|
||||
}
|
||||
function g(string storage s) pure {
|
||||
bool x;
|
||||
require(x, E(7, s));
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,13 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
revert((E()));
|
||||
}
|
||||
function g() pure {
|
||||
bool x;
|
||||
require(x, (E()));
|
||||
}
|
||||
// ----
|
||||
// TypeError 6473: (43-46): Tuple component cannot be empty.
|
||||
// TypeError 4423: (42-47): Expected error or string.
|
||||
// TypeError 6473: (100-103): Tuple component cannot be empty.
|
||||
// TypeError 4423: (99-104): Expected error or string.
|
||||
@@ -0,0 +1,4 @@
|
||||
function Err() pure {}
|
||||
error Err();
|
||||
// ----
|
||||
// DeclarationError 2333: (23-35): Identifier already declared.
|
||||
@@ -0,0 +1,4 @@
|
||||
contract A { function Err() public pure {} }
|
||||
contract B is A { error Err(); }
|
||||
// ----
|
||||
// DeclarationError 9097: (63-75): Identifier already declared.
|
||||
@@ -0,0 +1,3 @@
|
||||
// TODO do we want to disallow this at all?
|
||||
error Error(uint);
|
||||
// ----
|
||||
@@ -0,0 +1,6 @@
|
||||
error MyError();
|
||||
error MyError2(uint x);
|
||||
contract C {
|
||||
error MyError3(uint x, bytes);
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,5 @@
|
||||
error E(uint a);
|
||||
function f() pure {
|
||||
revert(E({a: 2}));
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
require({error: E()});
|
||||
}
|
||||
// ----
|
||||
// TypeError 1886: (35-56): Named arguments cannot be used for this function call.
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
revert({error: E()});
|
||||
}
|
||||
// ----
|
||||
// TypeError 1886: (35-55): Named arguments cannot be used for this function call.
|
||||
@@ -0,0 +1,7 @@
|
||||
error E1();
|
||||
error E2();
|
||||
function f() pure {
|
||||
revert(E1(E2));
|
||||
}
|
||||
// ----
|
||||
// TypeError 6160: (55-61): Wrong argument count for function call: 1 arguments given but expected 0.
|
||||
@@ -0,0 +1,7 @@
|
||||
error E1(uint);
|
||||
error E2();
|
||||
function f() pure {
|
||||
revert(E1(E2));
|
||||
}
|
||||
// ----
|
||||
// TypeError 9553: (62-64): Invalid type for argument in function call. Invalid implicit conversion from function () pure to uint256 requested.
|
||||
@@ -0,0 +1,7 @@
|
||||
error E1(uint);
|
||||
error E2();
|
||||
function f() pure {
|
||||
revert(E1(E2));
|
||||
}
|
||||
// ----
|
||||
// TypeError 9553: (62-64): Invalid type for argument in function call. Invalid implicit conversion from function () pure to uint256 requested.
|
||||
@@ -0,0 +1,7 @@
|
||||
error E1(uint);
|
||||
error E2();
|
||||
function f() pure {
|
||||
revert(E1([E2()]));
|
||||
}
|
||||
// ----
|
||||
// TypeError 5604: (63-67): Array component cannot be empty.
|
||||
@@ -0,0 +1,9 @@
|
||||
error MyError(mapping(uint => uint));
|
||||
contract C {
|
||||
error MyError2(mapping(uint => uint));
|
||||
}
|
||||
// ----
|
||||
// TypeError 3448: (14-35): Type containing a (nested) mapping is not allowed as error parameter type.
|
||||
// TypeError 3417: (14-35): Internal or recursive type is not allowed as error parameter type.
|
||||
// TypeError 3448: (70-91): Type containing a (nested) mapping is not allowed as error parameter type.
|
||||
// TypeError 3417: (70-91): Internal or recursive type is not allowed as error parameter type.
|
||||
@@ -0,0 +1,4 @@
|
||||
error Err(uint);
|
||||
error Err(bytes32);
|
||||
// ----
|
||||
// DeclarationError 2333: (17-36): Identifier already declared.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract A {
|
||||
error Err(uint);
|
||||
}
|
||||
contract B is A {
|
||||
error Err(bytes32);
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 9097: (58-77): Identifier already declared.
|
||||
@@ -0,0 +1,7 @@
|
||||
pragma abicoder v1;
|
||||
struct S {uint a;}
|
||||
contract C {
|
||||
error MyError(S);
|
||||
}
|
||||
// ----
|
||||
// TypeError 3061: (70-71): This type is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
|
||||
@@ -0,0 +1,4 @@
|
||||
// TODO: What if an error is imported and alias as Panic?
|
||||
// TODO I Think the best way would be to have Error in the global scope.
|
||||
error Panic(bytes2);
|
||||
// ----
|
||||
@@ -0,0 +1,6 @@
|
||||
// Test that the parser workaround is not breaking.
|
||||
struct error {uint a;}
|
||||
contract C {
|
||||
error x;
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
E();
|
||||
}
|
||||
// ----
|
||||
// TypeError 7757: (35-38): Errors can only be created directly inside require or revert calls.
|
||||
@@ -0,0 +1,7 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
// TODO is it a problem that we do not get an error here?
|
||||
// we should at least get "statement has no effect"
|
||||
E;
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,6 @@
|
||||
error E1();
|
||||
function f() pure {
|
||||
revert(E1{gas: 10}());
|
||||
}
|
||||
// ----
|
||||
// TypeError 2193: (43-54): Function call options can only be set on external function calls or contract creations.
|
||||
@@ -0,0 +1,7 @@
|
||||
error E1();
|
||||
error E2();
|
||||
function f() pure {
|
||||
revert(E1);
|
||||
}
|
||||
// ----
|
||||
// TypeError 4423: (55-57): Expected error or string.
|
||||
@@ -0,0 +1,6 @@
|
||||
error E(uint,string);
|
||||
function f() pure {
|
||||
revert(E(2, 3));
|
||||
}
|
||||
// ----
|
||||
// TypeError 9553: (58-59): Invalid type for argument in function call. Invalid implicit conversion from int_const 3 to string memory requested.
|
||||
@@ -0,0 +1,10 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
require();
|
||||
require(true, E(), 8);
|
||||
revert(E(), 3);
|
||||
}
|
||||
// ----
|
||||
// TypeError 7445: (35-44): Function "require" needs 1 or 2 arguments, but provided 0.
|
||||
// TypeError 7445: (50-71): Function "require" needs 1 or 2 arguments, but provided 3.
|
||||
// TypeError 7445: (77-91): Function "revert" needs 0 or 1 arguments, but provided 2.
|
||||
@@ -5,4 +5,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (81-87): No matching declaration found after variable lookup.
|
||||
// Warning 6133: (81-87): Statement has no effect.
|
||||
|
||||
@@ -3,4 +3,4 @@ contract C {
|
||||
function f() pure public { require; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 2144: (101-108): No matching declaration found after variable lookup.
|
||||
// Warning 6133: (101-108): Statement has no effect.
|
||||
|
||||
@@ -26,4 +26,4 @@ contract C {
|
||||
// TypeError 5547: (401-404): Empty tuple on the left hand side.
|
||||
// TypeError 4289: (399-466): Compound assignment is not allowed for tuple types.
|
||||
// TypeError 7407: (410-466): Type bytes32 is not implicitly convertible to expected type tuple().
|
||||
// TypeError 9322: (389-396): No matching declaration found after argument-dependent lookup.
|
||||
// TypeError 2956: (399-466): Invalid type for argument in function call. Invalid implicit conversion from tuple() to bool requested.
|
||||
|
||||
Reference in New Issue
Block a user