Merge pull request #10542 from ethereum/fixConstantEv

Fix bug in constant evaluator.
This commit is contained in:
Alex Beregszaszi 2020-12-09 16:04:42 +00:00 committed by GitHub
commit 32f1f16b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -271,7 +271,8 @@ optional<TypedRational> ConstantEvaluator::evaluate(ASTNode const& _node)
if (auto const* varDecl = dynamic_cast<VariableDeclaration const*>(&_node)) if (auto const* varDecl = dynamic_cast<VariableDeclaration const*>(&_node))
{ {
solAssert(varDecl->isConstant(), ""); solAssert(varDecl->isConstant(), "");
if (!varDecl->value()) // In some circumstances, we do not yet have a type for the variable.
if (!varDecl->value() || !varDecl->type())
m_values[&_node] = nullopt; m_values[&_node] = nullopt;
else else
{ {

View File

@ -0,0 +1,3 @@
int[L] constant L = 6;
// ----
// TypeError 5462: (4-5): Invalid array length, expected integer literal or constant expression.

View File

@ -0,0 +1,5 @@
contract C {
int[L] constant L = 6;
}
// ----
// TypeError 5462: (21-22): Invalid array length, expected integer literal or constant expression.