mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
added documentation and one last test for struct creation inline
This commit is contained in:
parent
ac664e7f86
commit
9c29cf79cf
@ -317,7 +317,8 @@ by `msg.data`.
|
|||||||
Can state variables be initialized in-line?
|
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::
|
Examples::
|
||||||
|
|
||||||
@ -325,6 +326,7 @@ Examples::
|
|||||||
struct S { uint a; uint b; }
|
struct S { uint a; uint b; }
|
||||||
S public x = S(1, 2);
|
S public x = S(1, 2);
|
||||||
string name = "Ada";
|
string name = "Ada";
|
||||||
|
string[4] memory AdaArr = ["This", "is", "an", "array"];
|
||||||
}
|
}
|
||||||
contract D {
|
contract D {
|
||||||
C c = new C();
|
C c = new C();
|
||||||
|
@ -2850,6 +2850,22 @@ BOOST_AUTO_TEST_CASE(inline_array_declaration_no_type_strings)
|
|||||||
BOOST_CHECK(success(text));
|
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)
|
BOOST_AUTO_TEST_CASE(invalid_types_in_inline_array)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user