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,20 @@
|
||||
library L {
|
||||
error E();
|
||||
}
|
||||
library S {
|
||||
error E(uint);
|
||||
}
|
||||
library T {
|
||||
error E();
|
||||
}
|
||||
contract C {
|
||||
function f() public pure returns (bytes4, bytes4) {
|
||||
assert(L.E.selector == T.E.selector);
|
||||
assert(L.E.selector != S.E.selector);
|
||||
return (L.E.selector, S.E.selector);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x92bbf6e800000000000000000000000000000000000000000000000000000000, 0x2ff06700000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,9 @@
|
||||
error E(uint);
|
||||
contract C {
|
||||
function f() public pure returns (bytes memory) {
|
||||
return abi.decode(msg.data, (E));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1039: (119-120): Argument has to be a type name.
|
||||
// TypeError 5132: (90-122): Different number of arguments in return statement than in returns declaration.
|
||||
@@ -0,0 +1,8 @@
|
||||
error E(uint);
|
||||
contract C {
|
||||
function f() public pure returns (bytes memory) {
|
||||
return abi.encode(E);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2056: (108-109): This type cannot be encoded.
|
||||
@@ -0,0 +1,8 @@
|
||||
error E(uint);
|
||||
contract C {
|
||||
function f() public pure returns (bytes memory) {
|
||||
return abi.encode(E(2));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 2056: (108-112): This type cannot be encoded.
|
||||
@@ -0,0 +1,8 @@
|
||||
error test266151307();
|
||||
contract C {
|
||||
error test266151307();
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (40-62): This declaration shadows an existing declaration.
|
||||
// SyntaxError 2855: (0-22): The selector 0xffffffff is reserved. Please rename the error to avoid the collision.
|
||||
// SyntaxError 2855: (40-62): The selector 0xffffffff is reserved. Please rename the error to avoid the collision.
|
||||
@@ -0,0 +1,3 @@
|
||||
error E() anonymous;
|
||||
// ----
|
||||
// ParserError 2314: (10-19): Expected ';' but got 'anonymous'
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
function f(bool x) pure {
|
||||
assert(x, E());
|
||||
}
|
||||
// ----
|
||||
// TypeError 6160: (41-55): Wrong argument count for function call: 2 arguments given but expected 1.
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
function f() pure {
|
||||
assert(E());
|
||||
}
|
||||
// ----
|
||||
// TypeError 9553: (42-45): Invalid type for argument in function call. Invalid implicit conversion from tuple() to bool requested.
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
error MyError();
|
||||
error MyError2(uint x);
|
||||
error MyError3(uint x, bytes);
|
||||
}
|
||||
// ----
|
||||
@@ -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,5 @@
|
||||
contract A { function Err() public pure {} }
|
||||
contract B { error Err(); }
|
||||
contract C is A, B {}
|
||||
// ----
|
||||
// DeclarationError 9097: (58-70): Identifier already declared.
|
||||
@@ -0,0 +1,2 @@
|
||||
error E(address payable x);
|
||||
// ----
|
||||
@@ -0,0 +1,4 @@
|
||||
error E(uint);
|
||||
function f(E x) pure returns (uint) {}
|
||||
// ----
|
||||
// TypeError 5172: (26-27): Name has to refer to a struct, enum or contract.
|
||||
@@ -0,0 +1,4 @@
|
||||
interface C {
|
||||
error E(uint);
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,4 @@
|
||||
library L {
|
||||
error E(uint);
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,3 @@
|
||||
error E(uint[] memory);
|
||||
// ----
|
||||
// ParserError 2314: (15-21): Expected ',' but got 'memory'
|
||||
@@ -0,0 +1,3 @@
|
||||
error E(uint[] calldata);
|
||||
// ----
|
||||
// ParserError 2314: (15-23): Expected ',' but got 'calldata'
|
||||
@@ -0,0 +1,3 @@
|
||||
error Error(uint);
|
||||
// ----
|
||||
// SyntaxError 1855: (0-18): The built-in errors "Error" and "Panic" cannot be re-defined.
|
||||
@@ -0,0 +1,6 @@
|
||||
error MyError();
|
||||
error MyError2(uint x);
|
||||
contract C {
|
||||
error MyError3(uint x, bytes);
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,6 @@
|
||||
contract test {
|
||||
error gsf();
|
||||
error tgeo();
|
||||
}
|
||||
// ----
|
||||
// TypeError 4883: (0-52): Error signature hash collision for tgeo()
|
||||
@@ -0,0 +1,3 @@
|
||||
error E(uint indexed);
|
||||
// ----
|
||||
// ParserError 2314: (13-20): Expected ',' but got 'indexed'
|
||||
@@ -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,3 @@
|
||||
error Panic(bytes2);
|
||||
// ----
|
||||
// SyntaxError 1855: (0-20): The built-in errors "Error" and "Panic" cannot be re-defined.
|
||||
@@ -0,0 +1,6 @@
|
||||
error E();
|
||||
|
||||
contract C {
|
||||
bytes4 t = E.selector;
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,7 @@
|
||||
error E();
|
||||
|
||||
contract C {
|
||||
bytes4 t = E().selector;
|
||||
}
|
||||
// ----
|
||||
// TypeError 9582: (40-52): Member "selector" not found or not visible after argument-dependent lookup in tuple().
|
||||
@@ -0,0 +1,6 @@
|
||||
// Test that the parser workaround is not breaking.
|
||||
struct error {uint a;}
|
||||
contract C {
|
||||
error x;
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,12 @@
|
||||
error E(uint);
|
||||
library L {
|
||||
function f(uint) internal {}
|
||||
}
|
||||
contract C {
|
||||
using L for *;
|
||||
function f() public pure {
|
||||
E.f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9582: (133-136): Member "f" not found or not visible after argument-dependent lookup in function (uint256) pure.
|
||||
@@ -0,0 +1,12 @@
|
||||
error E(uint);
|
||||
library L {
|
||||
function f(uint) internal {}
|
||||
}
|
||||
contract C {
|
||||
using L for E;
|
||||
function f() public pure {
|
||||
E.f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 5172: (91-92): Name has to refer to a struct, enum or contract.
|
||||
@@ -0,0 +1,6 @@
|
||||
struct S {uint a;}
|
||||
contract C {
|
||||
error MyError(S);
|
||||
error MyError2(S t);
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,7 @@
|
||||
error E();
|
||||
|
||||
contract C {
|
||||
function() internal pure x = E;
|
||||
}
|
||||
// ----
|
||||
// TypeError 7407: (58-59): Type function () pure is not implicitly convertible to expected type function () pure. Special functions can not be converted to function types.
|
||||
@@ -0,0 +1,7 @@
|
||||
error E();
|
||||
|
||||
contract C {
|
||||
E x;
|
||||
}
|
||||
// ----
|
||||
// TypeError 5172: (29-30): Name has to refer to a struct, enum or contract.
|
||||
@@ -0,0 +1,9 @@
|
||||
error E();
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
E x;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 5172: (64-65): Name has to refer to a struct, enum or contract.
|
||||
@@ -0,0 +1,8 @@
|
||||
error buyAndFree22457070633(uint256);
|
||||
contract C {
|
||||
error buyAndFree22457070633(uint256);
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (55-92): This declaration shadows an existing declaration.
|
||||
// SyntaxError 2855: (0-37): The selector 0x00000000 is reserved. Please rename the error to avoid the collision.
|
||||
// SyntaxError 2855: (55-92): The selector 0x00000000 is reserved. Please rename the error to avoid the collision.
|
||||
Reference in New Issue
Block a user