mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3745 from ethereum/fixRecursion
Fix invalid recursion errors for structs
This commit is contained in:
@@ -92,61 +92,6 @@ BOOST_AUTO_TEST_CASE(reference_to_later_declaration)
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_directly_recursive)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
struct MyStructName {
|
||||
address addr;
|
||||
MyStructName x;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "Recursive struct definition.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_indirectly_recursive)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
struct MyStructName1 {
|
||||
address addr;
|
||||
uint256 count;
|
||||
MyStructName2 x;
|
||||
}
|
||||
struct MyStructName2 {
|
||||
MyStructName1 x;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "Recursive struct definition.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_not_really_recursive)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
struct s1 { uint a; }
|
||||
struct s2 { s1 x; s1 y; }
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_recursion_via_mapping)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
struct MyStructName1 {
|
||||
address addr;
|
||||
uint256 count;
|
||||
mapping(uint => MyStructName1) x;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_inference_smoke_test)
|
||||
{
|
||||
char const* text = R"(
|
||||
@@ -6222,44 +6167,6 @@ BOOST_AUTO_TEST_CASE(read_returned_struct)
|
||||
)";
|
||||
CHECK_WARNING(text, "Experimental features");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(return_recursive_structs)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
struct S { uint a; S[] sub; }
|
||||
function f() returns (uint, S) {
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(return_recursive_structs2)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
struct S { uint a; S[2][] sub; }
|
||||
function f() returns (uint, S) {
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(return_recursive_structs3)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
struct S { uint a; S[][][] sub; }
|
||||
struct T { S s; }
|
||||
function f() returns (uint x, T t) {
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(address_checksum_type_deduction)
|
||||
{
|
||||
char const* text = R"(
|
||||
@@ -6382,38 +6289,6 @@ BOOST_AUTO_TEST_CASE(address_methods)
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cyclic_dependency_for_constants)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
uint constant a = a;
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "cyclic dependency via a");
|
||||
text = R"(
|
||||
contract C {
|
||||
uint constant a = b * c;
|
||||
uint constant b = 7;
|
||||
uint constant c = b + uint(keccak256(d));
|
||||
uint constant d = 2 + a;
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{
|
||||
"a has a cyclic dependency via c",
|
||||
"c has a cyclic dependency via d",
|
||||
"d has a cyclic dependency via a"
|
||||
}));
|
||||
text = R"(
|
||||
contract C {
|
||||
uint constant a = b * c;
|
||||
uint constant b = 7;
|
||||
uint constant c = 4 + uint(keccak256(d));
|
||||
uint constant d = 2 + b;
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(interface)
|
||||
{
|
||||
char const* text = R"(
|
||||
|
||||
Reference in New Issue
Block a user