From cc585138bc08ff421a026d08f07020b284d946ce Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Thu, 5 Jul 2018 12:31:46 +0200 Subject: Generates a syntax error when declaring a variable declaration's LHS has no named components --- libsolidity/analysis/SyntaxChecker.cpp | 13 +++++++++++++ libsolidity/analysis/SyntaxChecker.h | 2 ++ 2 files changed, 15 insertions(+) (limited to 'libsolidity/analysis') diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 4311e77d..e33aafed 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using namespace std; using namespace dev; @@ -254,6 +255,18 @@ bool SyntaxChecker::visit(FunctionTypeName const& _node) return true; } +bool SyntaxChecker::visit(VariableDeclarationStatement const& _statement) +{ + // Report if none of the variable components in the tuple have a name (only possible via deprecated "var") + if (boost::algorithm::all_of_equal(_statement.declarations(), nullptr)) + m_errorReporter.syntaxError( + _statement.location(), + "The use of the \"var\" keyword is disallowed. The declaration part of the statement can be removed, since it is empty." + ); + + return true; +} + bool SyntaxChecker::visit(StructDefinition const& _struct) { if (_struct.members().empty()) diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index 8ee3df37..5460e3be 100644 --- a/libsolidity/analysis/SyntaxChecker.h +++ b/libsolidity/analysis/SyntaxChecker.h @@ -69,6 +69,8 @@ private: virtual bool visit(FunctionDefinition const& _function) override; virtual bool visit(FunctionTypeName const& _node) override; + virtual bool visit(VariableDeclarationStatement const& _statement) override; + virtual bool visit(StructDefinition const& _struct) override; ErrorReporter& m_errorReporter; -- cgit v1.2.3