Merge pull request #8665 from ethereum/recursiveStructRefactoring

Recursive struct refactoring and a bunch of ICE fixes.
This commit is contained in:
chriseth
2020-04-20 13:24:19 +02:00
committed by GitHub
33 changed files with 445 additions and 206 deletions
+1
View File
@@ -184,6 +184,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
BOOST_CHECK_EQUAL(ContractType(c, true).identifier(), "t_super$_MyContract$$$_$2");
StructDefinition s(++id, {}, make_shared<string>("Struct"), {});
s.annotation().recursive = false;
BOOST_CHECK_EQUAL(s.type()->identifier(), "t_type$_t_struct$_Struct_$3_storage_ptr_$");
EnumDefinition e(++id, {}, make_shared<string>("Enum"), {});
@@ -0,0 +1,14 @@
contract C {
function f() public pure
{
bytes32[1263941234127518272][500] memory x;
uint[2**30][] memory y;
uint[2**30][2**30][] memory z;
uint[2**16][2**16][] memory w;
}
}
// ----
// TypeError: (48-90): Type too large for memory.
// TypeError: (96-118): Type too large for memory.
// TypeError: (124-153): Type too large for memory.
// TypeError: (159-188): Type too large for memory.
@@ -2,4 +2,4 @@ contract C {
function f(bytes32[1263941234127518272] memory) public pure {}
}
// ----
// TypeError: (26-61): Array is too large to be encoded.
// TypeError: (26-61): Type too large for memory.
@@ -5,7 +5,7 @@ contract C {
function f(uint[2**16][2**16][] memory) public pure {}
}
// ----
// TypeError: (26-66): Array is too large to be encoded.
// TypeError: (96-116): Array is too large to be encoded.
// TypeError: (146-173): Array is too large to be encoded.
// TypeError: (203-230): Array is too large to be encoded.
// TypeError: (26-66): Type too large for memory.
// TypeError: (96-116): Type too large for memory.
// TypeError: (146-173): Type too large for memory.
// TypeError: (203-230): Type too large for memory.
@@ -5,5 +5,5 @@ contract C {
function f(uint[2**30][2**30][][] memory) public pure {}
}
// ----
// TypeError: (61-101): Array is too large to be encoded.
// TypeError: (131-160): Array is too large to be encoded.
// TypeError: (61-101): Type too large for memory.
// TypeError: (131-160): Type too large for memory.
@@ -0,0 +1,5 @@
contract C {
function ( uint ) external returns ( a [ ] calldata ) public a = ( 1 / 2 ) ;
}
// ----
// TypeError: (58-59): Name has to refer to a struct, enum or contract.
@@ -0,0 +1,17 @@
contract C {
struct X { bytes31 [ 3 ] x1 ;
uint x2 ;
}
struct S { uint256 [ ] [ 0.425781 ether ] s1 ;
uint [ 2 ** 0xFF ] [ 2 ** 0x42 ] s2 ;
X s3 ;
mapping ( uint => address payable ) c ;
uint [ 9 hours ** 16 ] d ;
string s ;
}
function f ( ) public { function ( function ( bytes9 , uint ) external pure returns ( uint ) , uint ) external pure returns ( uint ) [ 3 ] memory s2 ;
S memory s ;
}
}
// ----
// TypeError: (530-540): Type too large for memory.
@@ -0,0 +1,12 @@
contract C {
struct R { uint[10][10] y; }
struct S { uint a; uint b; R d; uint[20][20][2999999999999999999999999990] c; }
function f() public pure {
C.S memory y;
C.S[10] memory z;
y.a < 2;
z; y;
}
}
// ----
// TypeError: (169-181): Type too large for memory.
@@ -7,3 +7,4 @@ contract C {
}
}
// ----
// TypeError: (226-234): Type too large for memory.
@@ -0,0 +1,7 @@
contract C {
function h ( bool flag ) public returns ( bool c ) {
mapping ( string => uint24 ) [ 1 ] memory val ;
}
}
// ----
// TypeError: (91-136): Data location must be "storage" for variable, but "memory" was given.
@@ -0,0 +1,13 @@
contract Test {
struct RecursiveStruct {
address payable d ;
mapping ( uint => address payable ) c ;
mapping ( uint => address payable [ ] ) d ;
}
function func ( ) private pure {
RecursiveStruct [ 1 ] memory val ;
val ;
}
}
// ----
// DeclarationError: (157-198): Identifier already declared.
@@ -4,4 +4,4 @@ contract C {
}
}
// ----
// TypeError: (47-77): Type mapping(uint256 => uint256)[] memory is only valid in storage.
// TypeError: (47-77): Data location must be "storage" for variable, but "memory" was given.
@@ -3,4 +3,4 @@ contract C {
}
}
// ----
// TypeError: (28-56): Array is too large to be encoded.
// TypeError: (28-56): Type too large for calldata.
@@ -3,4 +3,4 @@ contract C {
}
}
// ----
// TypeError: (28-54): Array is too large to be encoded.
// TypeError: (28-54): Type too large for memory.
@@ -3,4 +3,4 @@ contract C {
}
}
// ----
// TypeError: (28-54): Array is too large to be encoded.
// TypeError: (28-54): Type too large for memory.
@@ -4,7 +4,7 @@ contract C {
function f(Data.S memory a) public {}
}
contract Data {
struct S { S x; }
struct S { S[] x; }
}
// ----
// TypeError: (63-78): Recursive type not allowed for public or external contract functions.
@@ -0,0 +1,10 @@
pragma experimental ABIEncoderV2;
contract C {
struct S {
uint a;
function() external returns (S memory) sub;
}
function f() public pure returns (S memory) {
}
}
// ----
@@ -0,0 +1,7 @@
contract C {
struct S {
var x;
}
}
// ----
// ParserError: (27-30): Expected explicit type name.
@@ -257,4 +257,4 @@ contract Main {
struct JW { int i; }
}
// ----
// DeclarationError: (6091-6111): Struct definition exhausting cyclic dependency validator.
// DeclarationError: (6091-6111): Struct definition exhausts cyclic dependency validator.
@@ -0,0 +1,8 @@
struct s1 { s2 x; }
struct s2 { s1 y; }
contract C {
// whatever
}
// ----
// TypeError: (0-19): Recursive struct definition.
@@ -4,4 +4,3 @@ contract C {
}
// ----
// TypeError: (37-64): Data location must be "memory" for parameter in function, but "storage" was given.
// TypeError: (37-64): Internal type cannot be used for external function type.
@@ -4,4 +4,3 @@ contract C {
}
// ----
// TypeError: (57-84): Data location must be "memory" for return parameter in function, but "storage" was given.
// TypeError: (57-84): Internal type cannot be used for external function type.