From dc5ad899d0ff08aba7022a765e8ec363fa6c1f7e Mon Sep 17 00:00:00 2001 From: Jimmy Vogel Date: Mon, 22 Jan 2018 21:32:47 +0000 Subject: [PATCH] Deprecate the var keyword (and mark it an error as experimental 0.5.0 feature) --- Changelog.md | 1 + libsolidity/analysis/SyntaxChecker.cpp | 14 ++++++++++++++ libsolidity/analysis/SyntaxChecker.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/Changelog.md b/Changelog.md index 34fbf682f..db4252912 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ Features: * Inline Assembly: Support some restricted tokens (return, byte, address) as identifiers in Julia mode. * SMT Checker: If-else branch conditions are taken into account in the SMT encoding of the program variables. + * Syntax Checker: Deprecate the ``var`` keyword (and mark it an error as experimental 0.5.0 feature). * Type Checker: Issue warning for using ``public`` visibility for interface functions. Bugfixes: diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index b6cc04dac..5a3745b0a 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -224,3 +224,17 @@ bool SyntaxChecker::visit(FunctionTypeName const& _node) return true; } + +bool SyntaxChecker::visit(VariableDeclaration const& _declaration) +{ + bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050); + + if (!_declaration.typeName()) + { + if (v050) + m_errorReporter.syntaxError(_declaration.location(), "Use of the \"var\" keyword is deprecated."); + else + m_errorReporter.warning(_declaration.location(), "Use of the \"var\" keyword is deprecated."); + } + return true; +} diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index d5d72f143..871bf0a98 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(VariableDeclaration const& _declaration) override; + ErrorReporter& m_errorReporter; /// Flag that indicates whether a function modifier actually contains '_'.