mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Simplifies zero-length check for fixed-size arrays.
This commit is contained in:
parent
13a5890cc3
commit
e6d87e54c8
@ -231,8 +231,6 @@ void ReferencesResolver::endVisit(Mapping const& _typeName)
|
||||
void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
|
||||
{
|
||||
TypePointer baseType = _typeName.baseType().annotation().type;
|
||||
auto arrayType = dynamic_cast<ArrayType const*>(baseType.get());
|
||||
bool isFixedSizeArray = (arrayType && arrayType->isByteArray()) || !baseType->isDynamicallySized();
|
||||
if (!baseType)
|
||||
{
|
||||
solAssert(!m_errorReporter.errors().empty(), "");
|
||||
@ -243,12 +241,14 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
|
||||
if (Expression const* length = _typeName.length())
|
||||
{
|
||||
TypePointer lengthTypeGeneric = length->annotation().type;
|
||||
auto arrayType = dynamic_cast<ArrayType const*>(baseType.get());
|
||||
bool isByteOrFixedSizeArray = (arrayType && arrayType->isByteArray()) || !baseType->isDynamicallySized();
|
||||
if (!lengthTypeGeneric)
|
||||
lengthTypeGeneric = ConstantEvaluator(m_errorReporter).evaluate(*length);
|
||||
RationalNumberType const* lengthType = dynamic_cast<RationalNumberType const*>(lengthTypeGeneric.get());
|
||||
if (!lengthType || !lengthType->mobileType())
|
||||
fatalTypeError(length->location(), "Invalid array length, expected integer literal or constant expression.");
|
||||
else if (lengthType->isZero() && isFixedSizeArray)
|
||||
else if (lengthType->isZero() && isByteOrFixedSizeArray)
|
||||
fatalTypeError(length->location(), "Array with zero length specified.");
|
||||
else if (lengthType->isFractional())
|
||||
fatalTypeError(length->location(), "Array with fractional length specified.");
|
||||
|
Loading…
Reference in New Issue
Block a user