Tests for error syntax.

This commit is contained in:
chriseth 2021-02-08 18:46:17 +01:00
parent 16e01c1ed2
commit 3a2e4605a8
23 changed files with 105 additions and 11 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -8,6 +8,6 @@ function g() pure {
}
// ----
// TypeError 6473: (43-46): Tuple component cannot be empty.
// TypeError 4423: (42-47): Expected error or string.
// TypeError 4423: (42-47): Expected error instance or string.
// TypeError 6473: (100-103): Tuple component cannot be empty.
// TypeError 4423: (99-104): Expected error or string.
// TypeError 4423: (99-104): Expected error instance or string.

View File

@ -0,0 +1,2 @@
error E(address payable x);
// ----

View File

@ -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.

View File

@ -0,0 +1,4 @@
interface C {
error E(uint);
}
// ----

View File

@ -0,0 +1,4 @@
library L {
error E(uint);
}
// ----

View File

@ -0,0 +1,3 @@
error E(uint[] memory);
// ----
// ParserError 2314: (15-21): Expected ',' but got 'memory'

View File

@ -0,0 +1,3 @@
error E(uint[] calldata);
// ----
// ParserError 2314: (15-23): Expected ',' but got 'calldata'

View File

@ -1,3 +1,3 @@
error Error(uint);
// ----
// SyntaxError 1855: (44-62): The built-in errors "Error" and "Panic" cannot be re-defined.
// SyntaxError 1855: (0-18): The built-in errors "Error" and "Panic" cannot be re-defined.

View File

@ -0,0 +1,6 @@
contract test {
error gsf();
error tgeo();
}
// ----
// TypeError 4883: (0-52): Error signature hash collision for tgeo()

View File

@ -0,0 +1,3 @@
error E(uint indexed);
// ----
// ParserError 2314: (13-20): Expected ',' but got 'indexed'

View File

@ -3,4 +3,4 @@ function f() pure {
revert((E)());
}
// ----
// TypeError 4423: (42-47): Expected error or string.
// TypeError 4423: (42-47): Expected error instance or string.

View File

@ -1,7 +1,7 @@
error E1(uint);
error E1();
error E2();
function f() pure {
revert(E1(E2));
revert(E1(E2()));
}
// ----
// TypeError 9553: (62-64): Invalid type for argument in function call. Invalid implicit conversion from function () pure to uint256 requested.
// TypeError 6160: (55-63): Wrong argument count for function call: 1 arguments given but expected 0.

View File

@ -1,5 +1,3 @@
// 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);
// ----
// SyntaxError 1855: (131-151): The built-in errors "Error" and "Panic" cannot be re-defined.
// SyntaxError 1855: (0-20): The built-in errors "Error" and "Panic" cannot be re-defined.

View File

@ -4,4 +4,4 @@ function f() pure {
revert(E1);
}
// ----
// TypeError 4423: (55-57): Expected error or string.
// TypeError 4423: (55-57): Expected error instance or string. Did you forget the "()" after the error?

View File

@ -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.

View File

@ -0,0 +1,7 @@
error E();
contract C {
bytes4 t = E.selector;
}
// ----
// TypeError 9582: (40-50): Member "selector" not found or not visible after argument-dependent lookup in function () pure.

View File

@ -0,0 +1,7 @@
error E();
contract C {
E x;
}
// ----
// TypeError 5172: (29-30): Name has to refer to a struct, enum or contract.

View File

@ -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.