aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRJ Catalano <catalanor0220@gmail.com>2016-01-12 13:41:20 +0800
committerRJ Catalano <catalanor0220@gmail.com>2016-01-12 13:41:20 +0800
commitc45593a44480f846302fdb652e23bd47988fba84 (patch)
tree84226edd9239da911335f93641e5046766f2e55a
parentb230fe19052307d1b71372599ccaf8e1440e1473 (diff)
downloaddexon-solidity-c45593a44480f846302fdb652e23bd47988fba84.tar
dexon-solidity-c45593a44480f846302fdb652e23bd47988fba84.tar.gz
dexon-solidity-c45593a44480f846302fdb652e23bd47988fba84.tar.bz2
dexon-solidity-c45593a44480f846302fdb652e23bd47988fba84.tar.lz
dexon-solidity-c45593a44480f846302fdb652e23bd47988fba84.tar.xz
dexon-solidity-c45593a44480f846302fdb652e23bd47988fba84.tar.zst
dexon-solidity-c45593a44480f846302fdb652e23bd47988fba84.zip
clarification on dynamic arrays, switcheroo on typepointer, and a documentation test added
-rw-r--r--docs/frequently-asked-questions.rst2
-rw-r--r--libsolidity/analysis/TypeChecker.cpp2
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp17
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp4
4 files changed, 21 insertions, 4 deletions
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index 919ee54e..f87b785d 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -318,7 +318,7 @@ Can state variables be initialized in-line?
===========================================
Yes, this is possible for all types (even for structs). However, for arrays it
-should be noted that you must declare them as static memory arrays. Futhermore, multi dimensional arrays cannot be declared inline.
+should be noted that you must declare them as static memory arrays.
Examples::
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 3fb7303f..ab1151a1 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -784,7 +784,6 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
{
vector<ASTPointer<Expression>> const& components = _tuple.components();
TypePointers types;
- TypePointer inlineArrayType;
if (_tuple.annotation().lValueRequested)
{
@@ -807,6 +806,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
}
else
{
+ TypePointer inlineArrayType;
for (size_t i = 0; i < components.size(); ++i)
{
// Outside of an lvalue-context, the only situation where a component can be empty is (x,).
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 3136d43f..34c5dffc 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -6123,6 +6123,23 @@ BOOST_AUTO_TEST_CASE(inline_array_storage_to_memory_conversion_strings)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0x40), u256(0x80), u256(3), string("ray"), u256(2), string("mi")));
}
+BOOST_AUTO_TEST_CASE(inline_array_strings_from_document)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint i) returns (string) {
+ string[4] memory x = ["This", "is", "an", "array"];
+ return (x[i]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f(uint256)", u256(0)) == encodeArgs(u256(0x20), u256(4), string("This")));
+ BOOST_CHECK(callContractFunction("f(uint256)", u256(1)) == encodeArgs(u256(0x20), u256(2), string("is")));
+ BOOST_CHECK(callContractFunction("f(uint256)", u256(2)) == encodeArgs(u256(0x20), u256(2), string("an")));
+ BOOST_CHECK(callContractFunction("f(uint256)", u256(3)) == encodeArgs(u256(0x20), u256(5), string("array")));
+}
+
BOOST_AUTO_TEST_CASE(inline_array_storage_to_memory_conversion_ints)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 2281ac10..4697e756 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2883,11 +2883,11 @@ BOOST_AUTO_TEST_CASE(dynamic_inline_array)
char const* text = R"(
contract C {
function f() {
- uint[4][4] memory dyn = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]];
+ uint8[4][4] memory dyn = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]];
}
}
)";
- BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+ BOOST_CHECK(success(text));
}
BOOST_AUTO_TEST_CASE(lvalues_as_inline_array)