aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorBalajiganapathi S <balajiganapathi.s@gmail.com>2017-10-28 19:03:11 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-11-22 09:41:46 +0800
commit165857b1d40ecb8a1bcf40eec9e371370ebe2541 (patch)
tree7629b806e2e9ea4465a55ac2ea500f4ab568611d /test/libsolidity
parent5c9e273d028bdcc65af50fdc1a2c5545e54739c3 (diff)
downloaddexon-solidity-165857b1d40ecb8a1bcf40eec9e371370ebe2541.tar.gz
dexon-solidity-165857b1d40ecb8a1bcf40eec9e371370ebe2541.tar.zst
dexon-solidity-165857b1d40ecb8a1bcf40eec9e371370ebe2541.zip
Allow constant integer variables as array lengths.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp18
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp24
2 files changed, 41 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 9a837113..c2f96aaa 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2345,6 +2345,24 @@ BOOST_AUTO_TEST_CASE(constructor_static_array_argument)
ABI_CHECK(callContractFunction("b(uint256)", u256(2)), encodeArgs(u256(4)));
}
+BOOST_AUTO_TEST_CASE(constant_var_as_array_length)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint constant LEN = 3;
+ uint[LEN] public a;
+
+ function C(uint[LEN] _a) {
+ a = _a;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C", encodeArgs(u256(1), u256(2), u256(3)));
+ ABI_CHECK(callContractFunction("a(uint256)", u256(0)), encodeArgs(u256(1)));
+ ABI_CHECK(callContractFunction("a(uint256)", u256(1)), encodeArgs(u256(2)));
+ ABI_CHECK(callContractFunction("a(uint256)", u256(2)), encodeArgs(u256(3)));
+}
+
BOOST_AUTO_TEST_CASE(functions_called_by_constructor)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 88ec58ee..e00beefe 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2107,7 +2107,7 @@ BOOST_AUTO_TEST_CASE(array_with_nonconstant_length)
function f(uint a) public { uint8[a] x; }
}
)";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
+ CHECK_ERROR(text, TypeError, "Identifier must be declared constant");
}
BOOST_AUTO_TEST_CASE(array_with_negative_length)
@@ -7263,6 +7263,28 @@ BOOST_AUTO_TEST_CASE(array_length_not_convertible_to_integer)
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
}
+BOOST_AUTO_TEST_CASE(array_length_constant_var)
+{
+ char const* text = R"(
+ contract C {
+ uint constant LEN = 10;
+ uint[LEN] ids;
+ }
+ )";
+ CHECK_SUCCESS(text);
+}
+
+BOOST_AUTO_TEST_CASE(array_length_non_integer_constant_var)
+{
+ char const* text = R"(
+ contract C {
+ bool constant LEN = true;
+ uint[LEN] ids;
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
+}
+
BOOST_AUTO_TEST_CASE(array_length_invalid_expression)
{
char const* text = R"(