diff options
author | Erik Kundt <bitshift@posteo.org> | 2018-09-22 06:18:22 +0800 |
---|---|---|
committer | Erik Kundt <bitshift@posteo.org> | 2018-09-22 06:25:52 +0800 |
commit | d821cbdff5a483b3f7a7bd07758bf5e11a7cd762 (patch) | |
tree | 8e6a7c5c5da3d62c811f432f0c6fb6fa0b5728e9 /libsolidity | |
parent | ff5be1799088ca51fb51e9c86031bd2d88fe3bce (diff) | |
download | dexon-solidity-d821cbdff5a483b3f7a7bd07758bf5e11a7cd762.tar.gz dexon-solidity-d821cbdff5a483b3f7a7bd07758bf5e11a7cd762.tar.zst dexon-solidity-d821cbdff5a483b3f7a7bd07758bf5e11a7cd762.zip |
Moves length check to reference resolver.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/ReferencesResolver.cpp | 4 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 5 |
2 files changed, 4 insertions, 5 deletions
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 8a576e2e..30aa3d49 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -231,6 +231,8 @@ 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(), ""); @@ -246,6 +248,8 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName) 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) + fatalTypeError(length->location(), "Array with zero length specified."); else if (lengthType->isFractional()) fatalTypeError(length->location(), "Array with fractional length specified."); else if (lengthType->isNegative()) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 3b5e7b11..3056561b 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -822,17 +822,12 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) { case Type::Category::Array: if (auto arrayType = dynamic_cast<ArrayType const*>(varType.get())) - { if ( ((arrayType->location() == DataLocation::Memory) || (arrayType->location() == DataLocation::CallData)) && !arrayType->validForCalldata() ) m_errorReporter.typeError(_variable.location(), "Array is too large to be encoded."); - if (auto baseType = dynamic_cast<ArrayType const*>(arrayType->baseType().get())) - if (!baseType->isDynamicallySized() && baseType->length() == 0) - m_errorReporter.typeError(_variable.location(), "Fixed-size multidimensional arrays are not allowed to have zero length."); - } break; case Type::Category::Mapping: if (auto mappingType = dynamic_cast<MappingType const*>(varType.get())) |