mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5061 from ethereum/fixedSizeArrayLength
Disallow fixed-size arrays with zero length
This commit is contained in:
commit
13cd7c3fed
@ -84,6 +84,7 @@ Language Features:
|
|||||||
* General: Allow ``mapping`` storage pointers as arguments and return values in all internal functions.
|
* General: Allow ``mapping`` storage pointers as arguments and return values in all internal functions.
|
||||||
* General: Allow ``struct``s in interfaces.
|
* General: Allow ``struct``s in interfaces.
|
||||||
* General: Provide access to the ABI decoder through ``abi.decode(bytes memory data, (...))``.
|
* General: Provide access to the ABI decoder through ``abi.decode(bytes memory data, (...))``.
|
||||||
|
* General: Disallow zero length for fixed-size arrays.
|
||||||
* Parser: Accept the ``address payable`` type during parsing.
|
* Parser: Accept the ``address payable`` type during parsing.
|
||||||
|
|
||||||
Compiler Features:
|
Compiler Features:
|
||||||
@ -101,6 +102,7 @@ Bugfixes:
|
|||||||
* Tests: Fix chain parameters to make ipc tests work with newer versions of cpp-ethereum.
|
* Tests: Fix chain parameters to make ipc tests work with newer versions of cpp-ethereum.
|
||||||
* Code Generator: Fix allocation of byte arrays (zeroed out too much memory).
|
* Code Generator: Fix allocation of byte arrays (zeroed out too much memory).
|
||||||
* Code Generator: Properly handle negative number literals in ABIEncoderV2.
|
* Code Generator: Properly handle negative number literals in ABIEncoderV2.
|
||||||
|
* Code Generator: Do not crash on using a length of zero for multidimensional fixed-size arrays.
|
||||||
* Commandline Interface: Correctly handle paths with backslashes on windows.
|
* Commandline Interface: Correctly handle paths with backslashes on windows.
|
||||||
* Fix NatSpec json output for `@notice` and `@dev` tags on contract definitions.
|
* Fix NatSpec json output for `@notice` and `@dev` tags on contract definitions.
|
||||||
* Optimizer: Correctly estimate gas costs of constants for special cases.
|
* Optimizer: Correctly estimate gas costs of constants for special cases.
|
||||||
|
@ -222,6 +222,8 @@ Variables
|
|||||||
* Detecting cyclic dependencies in variables and structs is limited in
|
* Detecting cyclic dependencies in variables and structs is limited in
|
||||||
recursion to 256.
|
recursion to 256.
|
||||||
|
|
||||||
|
* Fixed-size arrays with a length of zero are now disallowed.
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -246,6 +246,8 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
|
|||||||
RationalNumberType const* lengthType = dynamic_cast<RationalNumberType const*>(lengthTypeGeneric.get());
|
RationalNumberType const* lengthType = dynamic_cast<RationalNumberType const*>(lengthTypeGeneric.get());
|
||||||
if (!lengthType || !lengthType->mobileType())
|
if (!lengthType || !lengthType->mobileType())
|
||||||
fatalTypeError(length->location(), "Invalid array length, expected integer literal or constant expression.");
|
fatalTypeError(length->location(), "Invalid array length, expected integer literal or constant expression.");
|
||||||
|
else if (lengthType->isZero())
|
||||||
|
fatalTypeError(length->location(), "Array with zero length specified.");
|
||||||
else if (lengthType->isFractional())
|
else if (lengthType->isFractional())
|
||||||
fatalTypeError(length->location(), "Array with fractional length specified.");
|
fatalTypeError(length->location(), "Array with fractional length specified.");
|
||||||
else if (lengthType->isNegative())
|
else if (lengthType->isNegative())
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
contract C {
|
||||||
|
function a() public pure returns(int[0][500] memory) {}
|
||||||
|
function b() public pure returns(uint[0][500] memory) {}
|
||||||
|
function c() public pure returns(byte[0][500] memory) {}
|
||||||
|
function d() public pure returns(bytes32[0][500] memory) {}
|
||||||
|
function e() public pure returns(bytes[0][500] memory) {}
|
||||||
|
function e() public pure returns(string[0][500] memory) {}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (52-53): Array with zero length specified.
|
||||||
|
// TypeError: (111-112): Array with zero length specified.
|
||||||
|
// TypeError: (170-171): Array with zero length specified.
|
||||||
|
// TypeError: (232-233): Array with zero length specified.
|
||||||
|
// TypeError: (292-293): Array with zero length specified.
|
||||||
|
// TypeError: (353-354): Array with zero length specified.
|
@ -0,0 +1,15 @@
|
|||||||
|
contract C {
|
||||||
|
int[0] a;
|
||||||
|
uint[0] b;
|
||||||
|
byte[0] c;
|
||||||
|
bytes32[0] d;
|
||||||
|
bytes[0] e;
|
||||||
|
string[0] f;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (19-20): Array with zero length specified.
|
||||||
|
// TypeError: (32-33): Array with zero length specified.
|
||||||
|
// TypeError: (45-46): Array with zero length specified.
|
||||||
|
// TypeError: (61-62): Array with zero length specified.
|
||||||
|
// TypeError: (75-76): Array with zero length specified.
|
||||||
|
// TypeError: (90-91): Array with zero length specified.
|
@ -21,5 +21,5 @@ contract C {
|
|||||||
uint[((2) + 1) + 1] a12;
|
uint[((2) + 1) + 1] a12;
|
||||||
uint[(2 + 1) + ((1))] a13;
|
uint[(2 + 1) + ((1))] a13;
|
||||||
uint[(((2) + 1)) + (((1)))] a14;
|
uint[(((2) + 1)) + (((1)))] a14;
|
||||||
uint[((((2) + 1)) + (((1))))%1] a15;
|
uint[((((3) + 1)) + (((1))))%2] a15;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
contract c {
|
contract c {
|
||||||
uint[10] a;
|
uint[10] a;
|
||||||
uint[] a2;
|
uint[] a2;
|
||||||
struct x { uint[2**20] b; y[0] c; }
|
struct x { uint[2**20] b; y[1] c; }
|
||||||
struct y { uint d; mapping(uint=>x)[] e; }
|
struct y { uint d; mapping(uint=>x)[] e; }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user