Disallow arrays with negative length

This commit is contained in:
Alex Beregszaszi
2017-02-02 00:24:45 +00:00
parent c01f5699e6
commit 697db80b48
3 changed files with 15 additions and 0 deletions
@@ -130,6 +130,8 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
auto const* lengthType = dynamic_cast<RationalNumberType const*>(length->annotation().type.get());
if (!lengthType || lengthType->isFractional())
fatalTypeError(length->location(), "Invalid array length, expected integer literal.");
else if (lengthType->isNegative())
fatalTypeError(length->location(), "Array with negative length specified.");
else
_typeName.annotation().type = make_shared<ArrayType>(DataLocation::Storage, baseType, lengthType->literalValue(nullptr));
}