From 762f7ac2508d119d1d1b66002c5498663a8d482f Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 5 Oct 2016 11:58:25 +0200 Subject: Suggest correct version for pragma and complain about pre-release version. --- libsolidity/analysis/SyntaxChecker.cpp | 17 +++++++++++++---- libsolidity/interface/CompilerStack.cpp | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index dc8c1806..dbaa15ed 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -52,13 +52,22 @@ void SyntaxChecker::endVisit(SourceUnit const& _sourceUnit) { if (!m_versionPragmaFound) { + string errorString("Source file does not specify required compiler version!"); + SemVerVersion recommendedVersion{string(VersionString)}; + if (!recommendedVersion.isPrerelease()) + errorString += + "Consider adding \"pragma solidity ^" + + to_string(recommendedVersion.major()) + + string(".") + + to_string(recommendedVersion.minor()) + + string(".") + + to_string(recommendedVersion.patch()); + string(";\""); + auto err = make_shared(Error::Type::Warning); *err << errinfo_sourceLocation(_sourceUnit.location()) << - errinfo_comment( - string("Source file does not specify required compiler version! ") + - string("Consider adding \"pragma solidity ^") + VersionNumber + string(";\".") - ); + errinfo_comment(errorString); m_errors.push_back(err); } } diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 476721db..efbbd237 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -21,8 +21,10 @@ * Full-stack compiler that converts a source code string to bytecode. */ -#include -#include +#include + +#include +#include #include #include #include @@ -32,12 +34,15 @@ #include #include #include -#include #include #include #include +#include +#include + + using namespace std; using namespace dev; using namespace dev::solidity; @@ -100,6 +105,13 @@ bool CompilerStack::parse() m_errors.clear(); m_parseSuccessful = false; + if (SemVerVersion{string(VersionString)}.isPrerelease()) + { + auto err = make_shared(Error::Type::Warning); + *err << errinfo_comment("This is a pre-release compiler version, please do not use it in production."); + m_errors.push_back(err); + } + vector sourcesToParse; for (auto const& s: m_sources) sourcesToParse.push_back(s.first); -- cgit