aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRJ Catalano <catalanor0220@gmail.com>2016-01-12 05:36:30 +0800
committerRJ Catalano <catalanor0220@gmail.com>2016-01-12 05:36:30 +0800
commit9c29cf79cf404132ec3ab149c492cfa97b677543 (patch)
tree2a839526306fbac3abd90076e1ced09ea97fd9af
parentac664e7f86593ff3d70576ac475f07f9c91b9ca8 (diff)
downloaddexon-solidity-9c29cf79cf404132ec3ab149c492cfa97b677543.tar.gz
dexon-solidity-9c29cf79cf404132ec3ab149c492cfa97b677543.tar.zst
dexon-solidity-9c29cf79cf404132ec3ab149c492cfa97b677543.zip
added documentation and one last test for struct creation inline
-rw-r--r--docs/frequently-asked-questions.rst4
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp16
2 files changed, 19 insertions, 1 deletions
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index cf037131..bf493167 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -317,7 +317,8 @@ by `msg.data`.
Can state variables be initialized in-line?
===========================================
-Yes, this is possible for most types (even for structs), but not for arrays.
+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.
Examples::
@@ -325,6 +326,7 @@ Examples::
struct S { uint a; uint b; }
S public x = S(1, 2);
string name = "Ada";
+ string[4] memory AdaArr = ["This", "is", "an", "array"];
}
contract D {
C c = new C();
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 3909fc6c..2281ac10 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2850,6 +2850,22 @@ BOOST_AUTO_TEST_CASE(inline_array_declaration_no_type_strings)
BOOST_CHECK(success(text));
}
+BOOST_AUTO_TEST_CASE(inline_struct_declaration_arrays)
+{
+ char const* text = R"(
+ contract C {
+ struct S {
+ uint a;
+ string b;
+ }
+ function f() {
+ S[2] memory x = [S({a: 1, b: "fish"}), S({a: 2, b: "fish"})];
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_CASE(invalid_types_in_inline_array)
{
char const* text = R"(