Merge pull request #1155 from ethereum/suggestcorrectversion

Suggest correct version for pragma.
This commit is contained in:
chriseth 2016-10-25 14:21:40 +02:00 committed by GitHub
commit e98d7f4ba4
2 changed files with 28 additions and 7 deletions

View File

@ -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>(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);
}
}

View File

@ -21,8 +21,10 @@
* Full-stack compiler that converts a source code string to bytecode.
*/
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <libsolidity/interface/CompilerStack.h>
#include <libsolidity/interface/Version.h>
#include <libsolidity/analysis/SemVerHandler.h>
#include <libsolidity/ast/AST.h>
#include <libsolidity/parsing/Scanner.h>
#include <libsolidity/parsing/Parser.h>
@ -32,12 +34,15 @@
#include <libsolidity/analysis/DocStringAnalyser.h>
#include <libsolidity/analysis/SyntaxChecker.h>
#include <libsolidity/codegen/Compiler.h>
#include <libsolidity/interface/CompilerStack.h>
#include <libsolidity/interface/InterfaceHandler.h>
#include <libsolidity/formal/Why3Translator.h>
#include <libdevcore/SHA3.h>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
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>(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<string> sourcesToParse;
for (auto const& s: m_sources)
sourcesToParse.push_back(s.first);