aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-27 21:44:41 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-05-16 09:52:24 +0800
commitc781baf7336af55abc33e1b63e6fc99a7e555d78 (patch)
tree1bab29687eaa45b50e6f241a9bac9de8a8018fe7 /test
parent67d208d144a179e52e1aab3fbd1bd67fe20176b7 (diff)
downloaddexon-solidity-c781baf7336af55abc33e1b63e6fc99a7e555d78.tar.gz
dexon-solidity-c781baf7336af55abc33e1b63e6fc99a7e555d78.tar.zst
dexon-solidity-c781baf7336af55abc33e1b63e6fc99a7e555d78.zip
Add tests for multi variable declaration statement.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp27
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol6
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol11
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalid.sol8
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalidType.sol9
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol12
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol13
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol12
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationThatIsExpression.sol9
9 files changed, 107 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 2db2aadd..42f69099 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -7610,6 +7610,33 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
ABI_CHECK(callContractFunction("f()", encodeArgs()), encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(typed_multi_variable_declaration)
+{
+ char const* sourceCode = R"(
+ contract C {
+ struct S { uint x; }
+ S s;
+ function g() internal returns (uint, S storage, uint) {
+ s.x = 7;
+ return (1, s, 2);
+ }
+ function f() returns (bool) {
+ (uint x1, S storage y1, uint z1) = g();
+ if (x1 != 1 || y1.x != 7 || z1 != 2) return false;
+ (, S storage y2,) = g();
+ if (y2.x != 7) return false;
+ (uint x2,,) = g();
+ if (x2 != 1) return false;
+ (,,uint z2) = g();
+ if (z2 != 2) return false;
+ return true;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()", encodeArgs()), encodeArgs(true));
+}
+
BOOST_AUTO_TEST_CASE(tuples)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol
new file mode 100644
index 00000000..182ba072
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() internal returns (uint) {
+ (uint a) = f();
+ a;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol
new file mode 100644
index 00000000..a3ce6a74
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol
@@ -0,0 +1,11 @@
+contract D {
+ struct S { uint a; uint b; }
+}
+contract C {
+ function f() internal returns (uint, uint, uint, D.S[20] storage, uint) {
+ (,,,D.S[10*2] storage x,) = f();
+ x;
+ }
+}
+// ----
+// Warning: (110-117): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalid.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalid.sol
new file mode 100644
index 00000000..c8686ae8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalid.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() internal returns (uint, uint, uint, uint) {
+ var (uint a, uint b,,) = f();
+ a; b;
+ }
+}
+// ----
+// ParserError: (81-85): Expected identifier but got 'uint'
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalidType.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalidType.sol
new file mode 100644
index 00000000..2b765837
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationInvalidType.sol
@@ -0,0 +1,9 @@
+contract C {
+ function f() internal returns (string memory, uint, uint, uint) {
+ (uint a, string memory b,,) = f();
+ a; b;
+ }
+}
+// ----
+// TypeError: (85-118): Type string memory is not implicitly convertible to expected type uint256.
+// TypeError: (85-118): Type uint256 is not implicitly convertible to expected type string memory.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol
new file mode 100644
index 00000000..3ba85f69
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping.sol
@@ -0,0 +1,12 @@
+pragma experimental "v0.5.0";
+
+contract C {
+ function f() internal {
+ {
+ (uint a, uint b, uint c) = (1, 2, 3);
+ }
+ a;
+ }
+}
+// ----
+// DeclarationError: (130-131): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol
new file mode 100644
index 00000000..e21181de
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationScoping2.sol
@@ -0,0 +1,13 @@
+pragma experimental "v0.5.0";
+
+contract C {
+ function f() internal {
+ {
+ (uint a, uint b, uint c) = (a, b, c);
+ }
+ }
+}
+// ----
+// DeclarationError: (110-111): Undeclared identifier. Did you mean "a"?
+// DeclarationError: (113-114): Undeclared identifier. Did you mean "b"?
+// DeclarationError: (116-117): Undeclared identifier. Did you mean "c"?
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol
new file mode 100644
index 00000000..8e06322c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol
@@ -0,0 +1,12 @@
+contract C {
+ function f() internal returns (uint, uint, uint, uint) {
+ (uint a, uint b,,) = f();
+ a; b;
+ }
+ function g() internal returns (bytes memory, string storage) {
+ (bytes memory a, string storage b) = g();
+ a; b;
+ }
+}
+// ----
+// Warning: (163-169): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationThatIsExpression.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationThatIsExpression.sol
new file mode 100644
index 00000000..8ae0eaac
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationThatIsExpression.sol
@@ -0,0 +1,9 @@
+contract C {
+ struct S { function() returns (S storage)[] x; }
+ S s;
+ function f() internal pure returns (uint, uint, uint, S storage, uint, uint) {
+ (,,,s.x[2](),,) = f();
+ }
+}
+// ----
+// TypeError: (160-168): Expression has to be an lvalue.