mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Improve error message for constant evaluator
This commit is contained in:
parent
45d0992ce8
commit
5226d54ed1
@ -150,7 +150,7 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
|
|||||||
ConstantEvaluator e(*length, m_errorReporter);
|
ConstantEvaluator e(*length, m_errorReporter);
|
||||||
auto const* lengthType = dynamic_cast<RationalNumberType const*>(length->annotation().type.get());
|
auto const* lengthType = dynamic_cast<RationalNumberType const*>(length->annotation().type.get());
|
||||||
if (!lengthType || !lengthType->mobileType())
|
if (!lengthType || !lengthType->mobileType())
|
||||||
fatalTypeError(length->location(), "Invalid array length, expected integer literal.");
|
fatalTypeError(length->location(), "Invalid array length, expected integer literal or constant expression.");
|
||||||
else if (lengthType->isFractional())
|
else if (lengthType->isFractional())
|
||||||
fatalTypeError(length->location(), "Array with fractional length specified.");
|
fatalTypeError(length->location(), "Array with fractional length specified.");
|
||||||
else if (lengthType->isNegative())
|
else if (lengthType->isNegative())
|
||||||
|
@ -257,7 +257,7 @@ public:
|
|||||||
}
|
}
|
||||||
virtual u256 literalValue(Literal const*) const
|
virtual u256 literalValue(Literal const*) const
|
||||||
{
|
{
|
||||||
solAssert(false, "Literal value requested for type without literals.");
|
solAssert(false, "Literal value requested for type without literals: " + toString(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns a (simpler) type that is encoded in the same way for external function calls.
|
/// @returns a (simpler) type that is encoded in the same way for external function calls.
|
||||||
|
@ -2109,7 +2109,7 @@ BOOST_AUTO_TEST_CASE(array_with_nonconstant_length)
|
|||||||
function f(uint a) public { uint8[a] x; }
|
function f(uint a) public { uint8[a] x; }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Identifier must be declared constant.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(array_with_negative_length)
|
BOOST_AUTO_TEST_CASE(array_with_negative_length)
|
||||||
@ -4398,7 +4398,7 @@ BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_signed_fixed_type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_unsigned_fixed_type)
|
BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_unsigned_fixed_type)
|
||||||
@ -4410,7 +4410,7 @@ BOOST_AUTO_TEST_CASE(invalid_array_declaration_with_unsigned_fixed_type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(rational_to_bytes_implicit_conversion)
|
BOOST_AUTO_TEST_CASE(rational_to_bytes_implicit_conversion)
|
||||||
@ -7254,7 +7254,7 @@ BOOST_AUTO_TEST_CASE(array_length_too_large)
|
|||||||
uint[8**90] ids;
|
uint[8**90] ids;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(array_length_not_convertible_to_integer)
|
BOOST_AUTO_TEST_CASE(array_length_not_convertible_to_integer)
|
||||||
@ -7264,7 +7264,7 @@ BOOST_AUTO_TEST_CASE(array_length_not_convertible_to_integer)
|
|||||||
uint[true] ids;
|
uint[true] ids;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(array_length_constant_var)
|
BOOST_AUTO_TEST_CASE(array_length_constant_var)
|
||||||
@ -7286,7 +7286,7 @@ BOOST_AUTO_TEST_CASE(array_length_non_integer_constant_var)
|
|||||||
uint[LEN] ids;
|
uint[LEN] ids;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(array_length_cannot_be_function)
|
BOOST_AUTO_TEST_CASE(array_length_cannot_be_function)
|
||||||
@ -7297,7 +7297,7 @@ BOOST_AUTO_TEST_CASE(array_length_cannot_be_function)
|
|||||||
uint[f] ids;
|
uint[f] ids;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(array_length_can_be_recursive_constant)
|
BOOST_AUTO_TEST_CASE(array_length_can_be_recursive_constant)
|
||||||
@ -7321,7 +7321,7 @@ BOOST_AUTO_TEST_CASE(array_length_cannot_be_function_call)
|
|||||||
uint[LEN] ids;
|
uint[LEN] ids;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(array_length_const_cannot_be_fractional)
|
BOOST_AUTO_TEST_CASE(array_length_const_cannot_be_fractional)
|
||||||
@ -7409,7 +7409,7 @@ BOOST_AUTO_TEST_CASE(array_length_with_pure_functions)
|
|||||||
uint[LEN] ids;
|
uint[LEN] ids;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
|
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(array_length_invalid_expression)
|
BOOST_AUTO_TEST_CASE(array_length_invalid_expression)
|
||||||
|
Loading…
Reference in New Issue
Block a user