mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Tests.
This commit is contained in:
parent
6d6914f98f
commit
644a402166
@ -321,6 +321,7 @@
|
||||
"names" : [],
|
||||
"nodeType" : "FunctionCall",
|
||||
"src" : "209:13:1",
|
||||
"tryCall" : false,
|
||||
"typeDescriptions" :
|
||||
{
|
||||
"typeIdentifier" : "t_address",
|
||||
@ -444,6 +445,7 @@
|
||||
"names" : [],
|
||||
"nodeType" : "FunctionCall",
|
||||
"src" : "239:10:1",
|
||||
"tryCall" : false,
|
||||
"typeDescriptions" :
|
||||
{
|
||||
"typeIdentifier" : "t_address_payable",
|
||||
|
@ -396,6 +396,7 @@
|
||||
[
|
||||
null
|
||||
],
|
||||
"tryCall" : false,
|
||||
"type" : "address",
|
||||
"type_conversion" : true
|
||||
},
|
||||
@ -526,6 +527,7 @@
|
||||
[
|
||||
null
|
||||
],
|
||||
"tryCall" : false,
|
||||
"type" : "address payable",
|
||||
"type_conversion" : true
|
||||
},
|
||||
|
@ -14784,6 +14784,59 @@ BOOST_AUTO_TEST_CASE(dirty_scratch_space_prior_to_constant_optimiser)
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(try_catch_library_call)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
library L {
|
||||
struct S { uint x; }
|
||||
function integer(uint t, bool b) public view returns (uint) {
|
||||
if (b) {
|
||||
return t;
|
||||
} else {
|
||||
revert("failure");
|
||||
}
|
||||
}
|
||||
function stru(S storage t, bool b) public view returns (uint) {
|
||||
if (b) {
|
||||
return t.x;
|
||||
} else {
|
||||
revert("failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
contract C {
|
||||
using L for L.S;
|
||||
L.S t;
|
||||
function f(bool b) public returns (uint, string memory) {
|
||||
uint x = 8;
|
||||
try L.integer(x, b) returns (uint _x) {
|
||||
return (_x, "");
|
||||
} catch Error(string memory message) {
|
||||
return (18, message);
|
||||
}
|
||||
}
|
||||
function g(bool b) public returns (uint, string memory) {
|
||||
t.x = 9;
|
||||
try t.stru(b) returns (uint x) {
|
||||
return (x, "");
|
||||
} catch Error(string memory message) {
|
||||
return (19, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
if (dev::test::Options::get().evmVersion().supportsReturndata())
|
||||
{
|
||||
compileAndRun(sourceCode, 0, "L", bytes());
|
||||
compileAndRun(sourceCode, 0, "C", bytes(), map<string, Address>{{"L", m_contractAddress}});
|
||||
|
||||
ABI_CHECK(callContractFunction("f(bool)", true), encodeArgs(8, 0x40, 0));
|
||||
ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(18, 0x40, 7, "failure"));
|
||||
ABI_CHECK(callContractFunction("g(bool)", true), encodeArgs(9, 0x40, 0));
|
||||
ABI_CHECK(callContractFunction("g(bool)", false), encodeArgs(19, 0x40, 7, "failure"));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,168 @@
|
||||
contract C {
|
||||
function g(bytes memory revertMsg) public pure returns (uint, uint) {
|
||||
assembly { revert(add(revertMsg, 0x20), mload(revertMsg)) }
|
||||
}
|
||||
function f1() public returns (uint x) {
|
||||
// Invalid signature
|
||||
try this.g(abi.encodeWithSelector(0x12345678, uint(0), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch (bytes memory) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f1a() public returns (uint x) {
|
||||
// Invalid signature
|
||||
try this.g(abi.encodeWithSelector(0x12345678, uint(0), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f1b() public returns (uint x) {
|
||||
// Invalid signature
|
||||
try this.g(abi.encodeWithSelector(0x12345678, uint(0), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
function f1c() public returns (uint x) {
|
||||
// Invalid signature
|
||||
try this.g(abi.encodeWithSelector(0x12345678, uint(0), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f2() public returns (uint x) {
|
||||
// Valid signature but illegal offset
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x100), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch (bytes memory) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f2a() public returns (uint x) {
|
||||
// Valid signature but illegal offset
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x100), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f2b() public returns (uint x) {
|
||||
// Valid signature but illegal offset
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x100), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
function f2c() public returns (uint x) {
|
||||
// Valid signature but illegal offset
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x100), uint(0), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
function f3() public returns (uint x) {
|
||||
// Valid up to length
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x30), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch (bytes memory) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f3a() public returns (uint x) {
|
||||
// Valid up to length
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x30), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch (bytes memory) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f3b() public returns (uint x) {
|
||||
// Valid up to length
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x30), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
function f3c() public returns (uint x) {
|
||||
// Valid up to length
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x30), uint(0))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
function f4() public returns (uint x) {
|
||||
// Fully valid
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x7), bytes7("abcdefg"))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch (bytes memory) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f4a() public returns (uint x) {
|
||||
// Fully valid
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x7), bytes7("abcdefg"))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
} catch {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
function f4b() public returns (uint x) {
|
||||
// Fully valid
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x7), bytes7("abcdefg"))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch Error(string memory) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
function f4c() public returns (uint x) {
|
||||
// Fully valid
|
||||
try this.g(abi.encodeWithSignature("Error(string)", uint(0x20), uint(0x7), bytes7("abcdefg"))) returns (uint a, uint b) {
|
||||
return 0;
|
||||
} catch {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f1() -> 2
|
||||
// f1a() -> 2
|
||||
// f1b() -> FAILURE, hex"12345678", 0x0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
// f1c() -> 2
|
||||
// f2() -> 2
|
||||
// f2a() -> 2
|
||||
// f2b() -> FAILURE, hex"08c379a0", 0x100, 0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
// f2c() -> 1
|
||||
// f3() -> 2
|
||||
// f3a() -> 2
|
||||
// f3b() -> FAILURE, hex"08c379a0", 0x20, 48, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
// f3c() -> 1
|
||||
// f4() -> 1
|
||||
// f4a() -> 1
|
||||
// f4b() -> 1
|
||||
// f4c() -> 1
|
18
test/libsolidity/semanticTests/tryCatch/lowLevel.sol
Normal file
18
test/libsolidity/semanticTests/tryCatch/lowLevel.sol
Normal file
@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
function g(bool b) public pure returns (uint, uint) {
|
||||
require(b, "message");
|
||||
return (1, 2);
|
||||
}
|
||||
function f(bool b) public returns (uint x, uint y, bytes memory txt) {
|
||||
try this.g(b) returns (uint a, uint b) {
|
||||
(x, y) = (a, b);
|
||||
} catch (bytes memory s) {
|
||||
txt = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f(bool): true -> 1, 2, 96, 0
|
||||
// f(bool): false -> 0, 0, 96, 100, 0x8c379a000000000000000000000000000000000000000000000000000000000, 0x2000000000000000000000000000000000000000000000000000000000, 0x76d657373616765000000000000000000000000000000000000000000, 0
|
33
test/libsolidity/semanticTests/tryCatch/nested.sol
Normal file
33
test/libsolidity/semanticTests/tryCatch/nested.sol
Normal file
@ -0,0 +1,33 @@
|
||||
contract C {
|
||||
function g(bool b) public pure returns (uint, uint) {
|
||||
require(b, "failure");
|
||||
return (1, 2);
|
||||
}
|
||||
function f(bool cond1, bool cond2) public returns (uint x, uint y, bytes memory txt) {
|
||||
try this.g(cond1) returns (uint a, uint b) {
|
||||
try this.g(cond2) returns (uint a2, uint b2) {
|
||||
(x, y) = (a, b);
|
||||
txt = "success";
|
||||
} catch Error(string memory s) {
|
||||
x = 12;
|
||||
txt = bytes(s);
|
||||
} catch (bytes memory s) {
|
||||
x = 13;
|
||||
txt = s;
|
||||
}
|
||||
} catch Error(string memory s) {
|
||||
x = 99;
|
||||
txt = bytes(s);
|
||||
} catch (bytes memory s) {
|
||||
x = 98;
|
||||
txt = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f(bool,bool): true, true -> 1, 2, 96, 7, "success"
|
||||
// f(bool,bool): true, false -> 12, 0, 96, 7, "failure"
|
||||
// f(bool,bool): false, true -> 99, 0, 96, 7, "failure"
|
||||
// f(bool,bool): false, false -> 99, 0, 96, 7, "failure"
|
17
test/libsolidity/semanticTests/tryCatch/return_function.sol
Normal file
17
test/libsolidity/semanticTests/tryCatch/return_function.sol
Normal file
@ -0,0 +1,17 @@
|
||||
contract C {
|
||||
function g() public returns (uint a, function() external h, uint b) {
|
||||
a = 1;
|
||||
h = this.fun;
|
||||
b = 9;
|
||||
}
|
||||
function f() public returns (uint, function() external, uint) {
|
||||
// Note that the function type uses two stack slots.
|
||||
try this.g() returns (uint a, function() external h, uint b) {
|
||||
return (a, h, b);
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
function fun() public pure {}
|
||||
}
|
||||
// ----
|
||||
// f() -> 0x1, 0xfdd67305928fcac8d213d1e47bfa6165cd0b87b946644cd0000000000000000, 9
|
18
test/libsolidity/semanticTests/tryCatch/simple.sol
Normal file
18
test/libsolidity/semanticTests/tryCatch/simple.sol
Normal file
@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
function g(bool b) public pure returns (uint, uint) {
|
||||
require(b);
|
||||
return (1, 2);
|
||||
}
|
||||
function f(bool b) public returns (uint x, uint y) {
|
||||
try this.g(b) returns (uint a, uint b) {
|
||||
(x, y) = (a, b);
|
||||
} catch {
|
||||
(x, y) = (9, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f(bool): true -> 1, 2
|
||||
// f(bool): false -> 9, 10
|
19
test/libsolidity/semanticTests/tryCatch/structured.sol
Normal file
19
test/libsolidity/semanticTests/tryCatch/structured.sol
Normal file
@ -0,0 +1,19 @@
|
||||
contract C {
|
||||
function g(bool b) public pure returns (uint, uint) {
|
||||
require(b, "message");
|
||||
return (1, 2);
|
||||
}
|
||||
function f(bool b) public returns (uint x, uint y, string memory txt) {
|
||||
try this.g(b) returns (uint a, uint b) {
|
||||
(x, y) = (a, b);
|
||||
txt = "success";
|
||||
} catch Error(string memory s) {
|
||||
txt = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f(bool): true -> 1, 2, 0x60, 7, "success"
|
||||
// f(bool): false -> 0, 0, 0x60, 7, "message"
|
@ -0,0 +1,23 @@
|
||||
contract C {
|
||||
function g(bool b) public pure returns (uint, uint) {
|
||||
require(b, "message longer than 32 bytes 32 bytes 32 bytes 32 bytes 32 bytes 32 bytes 32 bytes");
|
||||
return (1, 2);
|
||||
}
|
||||
function f(bool cond) public returns (uint x, uint y, bytes memory txt) {
|
||||
try this.g(cond) returns (uint a, uint b) {
|
||||
(x, y) = (a, b);
|
||||
txt = "success";
|
||||
} catch Error(string memory s) {
|
||||
x = 99;
|
||||
txt = bytes(s);
|
||||
} catch (bytes memory s) {
|
||||
x = 98;
|
||||
txt = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f(bool): true -> 1, 2, 96, 7, "success"
|
||||
// f(bool): false -> 99, 0, 96, 82, "message longer than 32 bytes 32 ", "bytes 32 bytes 32 bytes 32 bytes", " 32 bytes 32 bytes"
|
16
test/libsolidity/semanticTests/tryCatch/trivial.sol
Normal file
16
test/libsolidity/semanticTests/tryCatch/trivial.sol
Normal file
@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
function g(bool x) public pure {
|
||||
require(x);
|
||||
}
|
||||
function f(bool x) public returns (uint) {
|
||||
// Set the gas to make this work on pre-byzantium VMs
|
||||
try this.g.gas(8000)(x) {
|
||||
return 1;
|
||||
} catch {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f(bool): true -> 1
|
||||
// f(bool): false -> 2
|
11
test/libsolidity/syntaxTests/tryCatch/catch_error.sol
Normal file
11
test/libsolidity/syntaxTests/tryCatch/catch_error.sol
Normal file
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch Error(string memory) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
11
test/libsolidity/syntaxTests/tryCatch/catch_error_named.sol
Normal file
11
test/libsolidity/syntaxTests/tryCatch/catch_error_named.sol
Normal file
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch Error(string memory x) {
|
||||
x;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
11
test/libsolidity/syntaxTests/tryCatch/catch_low_level.sol
Normal file
11
test/libsolidity/syntaxTests/tryCatch/catch_low_level.sol
Normal file
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch (bytes memory x) {
|
||||
x;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
11
test/libsolidity/syntaxTests/tryCatch/empty_catch.sol
Normal file
11
test/libsolidity/syntaxTests/tryCatch/empty_catch.sol
Normal file
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch () {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (101-102): Expected type name
|
11
test/libsolidity/syntaxTests/tryCatch/empty_returns.sol
Normal file
11
test/libsolidity/syntaxTests/tryCatch/empty_returns.sol
Normal file
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
try this.f() returns () {
|
||||
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (69-70): Expected type name
|
@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch Error(uint) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// TypeError: (94-123): Expected `catch Error(string memory ...) { ... }`.
|
11
test/libsolidity/syntaxTests/tryCatch/invalid_error_name.sol
Normal file
11
test/libsolidity/syntaxTests/tryCatch/invalid_error_name.sol
Normal file
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
} catch Error2() {
|
||||
} catch abc() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (93-119): Invalid catch clause name. Expected either `catch (...)` or `catch Error(...)`.
|
||||
// TypeError: (120-143): Invalid catch clause name. Expected either `catch (...)` or `catch Error(...)`.
|
13
test/libsolidity/syntaxTests/tryCatch/invalid_returns.sol
Normal file
13
test/libsolidity/syntaxTests/tryCatch/invalid_returns.sol
Normal file
@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public returns (uint8, uint) {
|
||||
// Implicitly convertible, but not exactly the same type.
|
||||
try this.f() returns (uint, int x) {
|
||||
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (157-161): Invalid type, expected uint8 but got uint256.
|
||||
// TypeError: (163-168): Invalid type, expected uint256 but got int256.
|
40
test/libsolidity/syntaxTests/tryCatch/library_call.sol
Normal file
40
test/libsolidity/syntaxTests/tryCatch/library_call.sol
Normal file
@ -0,0 +1,40 @@
|
||||
library L {
|
||||
struct S { uint x; }
|
||||
function integer(uint t, bool b) public pure returns (uint) {
|
||||
if (b) {
|
||||
return t;
|
||||
} else {
|
||||
revert("failure");
|
||||
}
|
||||
}
|
||||
function stru(S storage t, bool b) public view returns (uint) {
|
||||
if (b) {
|
||||
return t.x;
|
||||
} else {
|
||||
revert("failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
contract C {
|
||||
using L for L.S;
|
||||
L.S t;
|
||||
function f(bool b) public pure returns (uint, string memory) {
|
||||
uint x = 8;
|
||||
try L.integer(x, b) returns (uint _x) {
|
||||
return (_x, "");
|
||||
} catch Error(string memory message) {
|
||||
return (18, message);
|
||||
}
|
||||
}
|
||||
function g(bool b) public returns (uint, string memory) {
|
||||
t.x = 9;
|
||||
try t.stru(b) returns (uint x) {
|
||||
return (x, "");
|
||||
} catch Error(string memory message) {
|
||||
return (19, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
try this.f() {
|
||||
|
||||
} catch (bytes memory) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: <byzantium
|
||||
// ----
|
||||
// TypeError: (73-106): This catch clause type cannot be used on the selected EVM version (homestead). You need at least a Byzantium-compatible EVM or use `catch { ... }`.
|
@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch (uint) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// TypeError: (94-118): Expected `catch (bytes memory ...) { ... }` or `catch { ... }`.
|
8
test/libsolidity/syntaxTests/tryCatch/no_catch.sol
Normal file
8
test/libsolidity/syntaxTests/tryCatch/no_catch.sol
Normal file
@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (97-98): Expected reserved keyword 'catch' but got '}'
|
@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try f() {
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (72-75): Try can only be used with external function calls and contract creation calls.
|
9
test/libsolidity/syntaxTests/tryCatch/no_returns.sol
Normal file
9
test/libsolidity/syntaxTests/tryCatch/no_returns.sol
Normal file
@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
10
test/libsolidity/syntaxTests/tryCatch/returns.sol
Normal file
10
test/libsolidity/syntaxTests/tryCatch/returns.sol
Normal file
@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() returns (uint a, uint b) {
|
||||
a = 1;
|
||||
b = 2;
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
test/libsolidity/syntaxTests/tryCatch/returns_memory.sol
Normal file
11
test/libsolidity/syntaxTests/tryCatch/returns_memory.sol
Normal file
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint[] memory, uint) {
|
||||
try this.f() returns (uint[] memory x, uint y) {
|
||||
return (x, y);
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint[] memory, uint) {
|
||||
try this.f() returns (uint[] memory, uint) {
|
||||
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
9
test/libsolidity/syntaxTests/tryCatch/simple_catch.sol
Normal file
9
test/libsolidity/syntaxTests/tryCatch/simple_catch.sol
Normal file
@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
try this.f() {
|
||||
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
try this.f() {
|
||||
|
||||
} catch Error(string memory) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: <byzantium
|
||||
// ----
|
||||
// TypeError: (73-112): This catch clause type cannot be used on the selected EVM version (homestead). You need at least a Byzantium-compatible EVM or use `catch { ... }`.
|
14
test/libsolidity/syntaxTests/tryCatch/two_catch_clauses.sol
Normal file
14
test/libsolidity/syntaxTests/tryCatch/two_catch_clauses.sol
Normal file
@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch Error(string memory x) {
|
||||
x;
|
||||
|
||||
} catch (bytes memory x) {
|
||||
x;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch Error(string memory x) {
|
||||
x;
|
||||
} catch Error(string memory y) {
|
||||
y;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// TypeError: (150-205): This try statement already has an "Error" catch clause.
|
@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
function f() public returns (uint, uint) {
|
||||
try this.f() {
|
||||
|
||||
} catch {
|
||||
} catch (bytes memory y) {
|
||||
y;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// TypeError: (112-161): This try statement already has a low-level catch clause.
|
18
test/libsolidity/syntaxTests/unusedVariables/try_catch.sol
Normal file
18
test/libsolidity/syntaxTests/unusedVariables/try_catch.sol
Normal file
@ -0,0 +1,18 @@
|
||||
contract test {
|
||||
function f() public returns (uint b) {
|
||||
try this.f() returns (uint a) {
|
||||
|
||||
} catch Error(string memory message) {
|
||||
|
||||
} catch (bytes memory error) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// Warning: (49-55): Unused function parameter. Remove or comment out the variable name to silence this warning.
|
||||
// Warning: (89-95): Unused try/catch parameter. Remove or comment out the variable name to silence this warning.
|
||||
// Warning: (122-143): Unused try/catch parameter. Remove or comment out the variable name to silence this warning.
|
||||
// Warning: (165-183): Unused try/catch parameter. Remove or comment out the variable name to silence this warning.
|
Loading…
Reference in New Issue
Block a user