mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5195 from ethereum/unsigned-array-index
Do not crash on non-unsigned array index
This commit is contained in:
@@ -2316,7 +2316,8 @@ bool TypeChecker::visit(IndexAccess const& _access)
|
||||
m_errorReporter.typeError(_access.location(), "Index expression cannot be omitted.");
|
||||
else
|
||||
{
|
||||
expectType(*index, IntegerType(256));
|
||||
if (!expectType(*index, IntegerType(256)))
|
||||
m_errorReporter.fatalTypeError(_access.location(), "Index expression cannot be represented as an unsigned integer.");
|
||||
if (auto integerType = dynamic_cast<RationalNumberType const*>(type(*index).get()))
|
||||
if (bytesType.numBytes() <= integerType->literalValue(nullptr))
|
||||
m_errorReporter.typeError(_access.location(), "Out of bounds array access.");
|
||||
@@ -2487,7 +2488,7 @@ Declaration const& TypeChecker::dereference(UserDefinedTypeName const& _typeName
|
||||
return *_typeName.annotation().referencedDeclaration;
|
||||
}
|
||||
|
||||
void TypeChecker::expectType(Expression const& _expression, Type const& _expectedType)
|
||||
bool TypeChecker::expectType(Expression const& _expression, Type const& _expectedType)
|
||||
{
|
||||
_expression.accept(*this);
|
||||
if (!type(_expression)->isImplicitlyConvertibleTo(_expectedType))
|
||||
@@ -2516,7 +2517,9 @@ void TypeChecker::expectType(Expression const& _expression, Type const& _expecte
|
||||
_expectedType.toString() +
|
||||
"."
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TypeChecker::requireLValue(Expression const& _expression)
|
||||
|
||||
@@ -143,7 +143,7 @@ private:
|
||||
|
||||
/// Runs type checks on @a _expression to infer its type and then checks that it is implicitly
|
||||
/// convertible to @a _expectedType.
|
||||
void expectType(Expression const& _expression, Type const& _expectedType);
|
||||
bool expectType(Expression const& _expression, Type const& _expectedType);
|
||||
/// Runs type checks on @a _expression to infer its type and then checks that it is an LValue.
|
||||
void requireLValue(Expression const& _expression);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user