diff options
author | Christian Parpart <christian@ethereum.org> | 2018-07-12 22:17:30 +0800 |
---|---|---|
committer | Christian Parpart <christian@ethereum.org> | 2018-08-01 15:59:06 +0800 |
commit | a7150f85a686bd2e96c01aa71f02fb0d762e0dd0 (patch) | |
tree | f14d447fe9a3b82c7b58f314bb3d527d766f1bc6 /libsolidity/analysis | |
parent | beb66db66feda8ef59176069eea393aa5884c5da (diff) | |
download | dexon-solidity-a7150f85a686bd2e96c01aa71f02fb0d762e0dd0.tar.gz dexon-solidity-a7150f85a686bd2e96c01aa71f02fb0d762e0dd0.tar.zst dexon-solidity-a7150f85a686bd2e96c01aa71f02fb0d762e0dd0.zip |
Ensures an empty use of var keyword is caught with the proper error message.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 8536e934..d2fb9281 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -22,6 +22,7 @@ #include <libsolidity/analysis/TypeChecker.h> #include <memory> +#include <boost/algorithm/cxx11/all_of.hpp> #include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/join.hpp> #include <boost/range/adaptor/reversed.hpp> @@ -709,6 +710,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) // TypeChecker at the VariableDeclarationStatement level. TypePointer varType = _variable.annotation().type; solAssert(!!varType, "Failed to infer variable type."); + if (_variable.value()) expectType(*_variable.value(), *varType); if (_variable.isConstant()) @@ -1079,10 +1081,25 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) { // No initial value is only permitted for single variables with specified type. if (_statement.declarations().size() != 1 || !_statement.declarations().front()) - m_errorReporter.fatalTypeError(_statement.location(), "Assignment necessary for type detection."); + { + if (boost::algorithm::all_of_equal(_statement.declarations(), nullptr)) + { + // The syntax checker has already generated an error for this case (empty LHS tuple). + solAssert(m_errorReporter.hasErrors(), ""); + + // It is okay to return here, as there are no named components on the + // left-hand-side that could cause any damage later. + return false; + } + else + // Bailing out *fatal* here, as those (untyped) vars may be used later, and diagnostics wouldn't be helpful then. + m_errorReporter.fatalTypeError(_statement.location(), "Use of the \"var\" keyword is disallowed."); + } + VariableDeclaration const& varDecl = *_statement.declarations().front(); if (!varDecl.annotation().type) - m_errorReporter.fatalTypeError(_statement.location(), "Assignment necessary for type detection."); + m_errorReporter.fatalTypeError(_statement.location(), "Use of the \"var\" keyword is disallowed."); + if (auto ref = dynamic_cast<ReferenceType const*>(type(varDecl).get())) { if (ref->dataStoredIn(DataLocation::Storage)) |