aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-08-04 21:16:23 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-08-04 22:22:22 +0800
commit83e6c345265c88c194416c2499af8afa3dc51e83 (patch)
tree1d62901acde7ee5d9f9db19ad3d16dcc3c41a67a
parent0b20e4fd22349da691056f3a4ac89c7c5006a0c4 (diff)
downloaddexon-solidity-83e6c345265c88c194416c2499af8afa3dc51e83.tar
dexon-solidity-83e6c345265c88c194416c2499af8afa3dc51e83.tar.gz
dexon-solidity-83e6c345265c88c194416c2499af8afa3dc51e83.tar.bz2
dexon-solidity-83e6c345265c88c194416c2499af8afa3dc51e83.tar.lz
dexon-solidity-83e6c345265c88c194416c2499af8afa3dc51e83.tar.xz
dexon-solidity-83e6c345265c88c194416c2499af8afa3dc51e83.tar.zst
dexon-solidity-83e6c345265c88c194416c2499af8afa3dc51e83.zip
Fix declaration suggestion for var with different number of components
-rw-r--r--libsolidity/analysis/TypeChecker.cpp6
-rw-r--r--test/libsolidity/syntaxTests/types/var_type_suggest.sol12
2 files changed, 18 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 8c84e4dc..f742fcc0 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1038,7 +1038,10 @@ string createTupleDecl(vector<ASTPointer<VariableDeclaration>> const& _decls)
vector<string> components;
for (ASTPointer<VariableDeclaration> const& decl: _decls)
if (decl)
+ {
+ solAssert(decl->annotation().type, "");
components.emplace_back(decl->annotation().type->toString(false) + " " + decl->name());
+ }
else
components.emplace_back();
@@ -1056,6 +1059,9 @@ bool typeCanBeExpressed(vector<ASTPointer<VariableDeclaration>> const& decls)
if (!decl)
continue;
+ if (!decl->annotation().type)
+ return false;
+
if (auto functionType = dynamic_cast<FunctionType const*>(decl->annotation().type.get()))
if (
functionType->kind() != FunctionType::Kind::Internal &&
diff --git a/test/libsolidity/syntaxTests/types/var_type_suggest.sol b/test/libsolidity/syntaxTests/types/var_type_suggest.sol
index 176fab96..cc35fdd6 100644
--- a/test/libsolidity/syntaxTests/types/var_type_suggest.sol
+++ b/test/libsolidity/syntaxTests/types/var_type_suggest.sol
@@ -12,6 +12,10 @@ contract C {
var myblockhash = block.blockhash;
var (a, b) = (2, "troi");
var (x,, z) = h();
+ var (c, d) = ("");
+ var (k, l) = (2);
+ var (m, n) = 1;
+ var (o, p) = "";
}
}
// ----
@@ -21,3 +25,11 @@ contract C {
// SyntaxError: (293-326): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
// SyntaxError: (336-360): Use of the "var" keyword is disallowed. Use explicit declaration `(uint8 a, string memory b) = ...´ instead.
// SyntaxError: (370-387): Use of the "var" keyword is disallowed. Use explicit declaration `(uint256 x, , uint256 z) = ...´ instead.
+// TypeError: (397-414): Different number of components on the left hand side (2) than on the right hand side (1).
+// SyntaxError: (397-414): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
+// TypeError: (424-440): Different number of components on the left hand side (2) than on the right hand side (1).
+// SyntaxError: (424-440): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
+// TypeError: (450-464): Different number of components on the left hand side (2) than on the right hand side (1).
+// SyntaxError: (450-464): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
+// TypeError: (474-489): Different number of components on the left hand side (2) than on the right hand side (1).
+// SyntaxError: (474-489): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.