Merge pull request #3745 from ethereum/fixRecursion

Fix invalid recursion errors for structs
This commit is contained in:
Alex Beregszaszi
2018-04-05 12:04:54 +02:00
committed by GitHub
19 changed files with 220 additions and 155 deletions
@@ -0,0 +1,5 @@
contract C {
uint constant a = a;
}
// ----
// TypeError: The value of the constant a has a cyclic dependency via a.
@@ -0,0 +1,10 @@
contract C {
uint constant a = b * c;
uint constant b = 7;
uint constant c = b + uint(keccak256(d));
uint constant d = 2 + a;
}
// ----
// TypeError: The value of the constant a has a cyclic dependency via c.
// TypeError: The value of the constant c has a cyclic dependency via d.
// TypeError: The value of the constant d has a cyclic dependency via a.
@@ -0,0 +1,11 @@
contract C {
uint constant x = a;
uint constant a = b * c;
uint constant b = c;
uint constant c = b;
}
// ----
// TypeError: The value of the constant x has a cyclic dependency via a.
// TypeError: The value of the constant a has a cyclic dependency via b.
// TypeError: The value of the constant b has a cyclic dependency via c.
// TypeError: The value of the constant c has a cyclic dependency via b.
@@ -0,0 +1,6 @@
contract C {
uint constant a = b * c;
uint constant b = 7;
uint constant c = 4 + uint(keccak256(d));
uint constant d = 2 + b;
}
@@ -0,0 +1,15 @@
pragma experimental ABIEncoderV2;
contract C {
struct T { U u; V v; }
struct U { W w; }
struct V { W w; }
struct W { uint x; }
function f(T) public pure { }
}
// ----
// Warning: Experimental features are turned on. Do not use experimental features on live deployments.
@@ -0,0 +1,15 @@
pragma experimental ABIEncoderV2;
contract TestContract
{
struct SubStruct {
uint256 id;
}
struct TestStruct {
SubStruct subStruct1;
SubStruct subStruct2;
}
function addTestStruct(TestStruct) public pure {}
}
// ----
// Warning: Experimental features are turned on. Do not use experimental features on live deployments.
@@ -0,0 +1,7 @@
contract C {
struct S { uint a; S[] sub; }
function f() public pure returns (uint, S) {
}
}
// ----
// TypeError: Internal or recursive type is not allowed for public or external functions.
@@ -0,0 +1,7 @@
contract C {
struct S { uint a; S[2][] sub; }
function f() public pure returns (uint, S) {
}
}
// ----
// TypeError: Internal or recursive type is not allowed for public or external functions.
@@ -0,0 +1,8 @@
contract C {
struct S { uint a; S[][][] sub; }
struct T { S s; }
function f() public pure returns (uint x, T t) {
}
}
// ----
// TypeError: Internal or recursive type is not allowed for public or external functions.
@@ -0,0 +1,8 @@
contract Test {
struct MyStructName {
address addr;
MyStructName x;
}
}
// ----
// TypeError: Recursive struct definition.
@@ -0,0 +1,12 @@
contract Test {
struct MyStructName1 {
address addr;
uint256 count;
MyStructName2 x;
}
struct MyStructName2 {
MyStructName1 x;
}
}
// ----
// TypeError: Recursive struct definition.
@@ -0,0 +1,4 @@
contract Test {
struct S1 { uint a; }
struct S2 { S1 x; S1 y; }
}
@@ -0,0 +1,7 @@
contract Test {
struct MyStructName1 {
address addr;
uint256 count;
mapping(uint => MyStructName1) x;
}
}