mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11606 from ethereum/info_message
Add new info severity
This commit is contained in:
@@ -75,24 +75,24 @@ AnalysisFramework::parseAnalyseAndReturnError(
|
||||
return make_pair(&compiler().ast(""), std::move(errors));
|
||||
}
|
||||
|
||||
ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _includeWarnings) const
|
||||
ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _includeWarningsAndInfos) const
|
||||
{
|
||||
ErrorList errors;
|
||||
for (auto const& currentError: _errorList)
|
||||
{
|
||||
solAssert(currentError->comment(), "");
|
||||
if (currentError->type() == Error::Type::Warning)
|
||||
if (!Error::isError(currentError->type()))
|
||||
{
|
||||
if (!_includeWarnings)
|
||||
if (!_includeWarningsAndInfos)
|
||||
continue;
|
||||
bool ignoreWarning = false;
|
||||
bool ignoreWarningsAndInfos = false;
|
||||
for (auto const& filter: m_warningsToFilter)
|
||||
if (currentError->comment()->find(filter) == 0)
|
||||
{
|
||||
ignoreWarning = true;
|
||||
ignoreWarningsAndInfos = true;
|
||||
break;
|
||||
}
|
||||
if (ignoreWarning)
|
||||
if (ignoreWarningsAndInfos)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ protected:
|
||||
std::string const& _signature
|
||||
);
|
||||
|
||||
// filter out the warnings in m_warningsToFilter or all warnings if _includeWarnings is false
|
||||
langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarnings) const;
|
||||
// filter out the warnings in m_warningsToFilter or all warnings and infos if _includeWarningsAndInfos is false
|
||||
langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarningsAndInfos) const;
|
||||
|
||||
std::vector<std::string> m_warningsToFilter = {"This is a pre-release compiler version"};
|
||||
std::vector<std::string> m_messagesToCut = {"Source file requires different compiler version (current compiler is"};
|
||||
|
||||
@@ -67,20 +67,20 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
|
||||
GlobalContext globalContext;
|
||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
|
||||
solAssert(Error::containsOnlyWarnings(errorReporter.errors()), "");
|
||||
solAssert(!Error::containsErrors(errorReporter.errors()), "");
|
||||
resolver.registerDeclarations(*sourceUnit);
|
||||
BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*sourceUnit));
|
||||
if (!Error::containsOnlyWarnings(errorReporter.errors()))
|
||||
if (Error::containsErrors(errorReporter.errors()))
|
||||
return AssemblyItems();
|
||||
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
||||
{
|
||||
BOOST_REQUIRE_NO_THROW(declarationTypeChecker.check(*node));
|
||||
if (!Error::containsOnlyWarnings(errorReporter.errors()))
|
||||
if (Error::containsErrors(errorReporter.errors()))
|
||||
return AssemblyItems();
|
||||
}
|
||||
TypeChecker checker(solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||
BOOST_REQUIRE_NO_THROW(checker.checkTypeRequirements(*sourceUnit));
|
||||
if (!Error::containsOnlyWarnings(errorReporter.errors()))
|
||||
if (Error::containsErrors(errorReporter.errors()))
|
||||
return AssemblyItems();
|
||||
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||
|
||||
@@ -128,7 +128,7 @@ void parsePrintCompare(string const& _source, bool _canWarn = false)
|
||||
AssemblyStack stack(solidity::test::CommonOptions::get().evmVersion(), AssemblyStack::Language::Assembly, OptimiserSettings::none());
|
||||
BOOST_REQUIRE(stack.parseAndAnalyze("", _source));
|
||||
if (_canWarn)
|
||||
BOOST_REQUIRE(Error::containsOnlyWarnings(stack.errors()));
|
||||
BOOST_REQUIRE(!Error::containsErrors(stack.errors()));
|
||||
else
|
||||
BOOST_REQUIRE(stack.errors().empty());
|
||||
string expectation = "object \"object\" {\n code " + boost::replace_all_copy(_source, "\n", "\n ") + "\n}\n";
|
||||
|
||||
@@ -74,7 +74,7 @@ bool successParse(std::string const& _source)
|
||||
if (Error::containsErrorOfType(errors, Error::Type::ParserError))
|
||||
return false;
|
||||
|
||||
BOOST_CHECK(Error::containsOnlyWarnings(errors));
|
||||
BOOST_CHECK(!Error::containsErrors(errors));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,19 @@ namespace solidity::frontend::test
|
||||
namespace
|
||||
{
|
||||
|
||||
langutil::Error::Severity str2Severity(string const& _cat)
|
||||
{
|
||||
map<string, langutil::Error::Severity> cats{
|
||||
{"info", langutil::Error::Severity::Info},
|
||||
{"Info", langutil::Error::Severity::Info},
|
||||
{"warning", langutil::Error::Severity::Warning},
|
||||
{"Warning", langutil::Error::Severity::Warning},
|
||||
{"error", langutil::Error::Severity::Error},
|
||||
{"Error", langutil::Error::Severity::Error}
|
||||
};
|
||||
return cats.at(_cat);
|
||||
}
|
||||
|
||||
/// Helper to match a specific error type and message
|
||||
bool containsError(Json::Value const& _compilerResult, string const& _type, string const& _message)
|
||||
{
|
||||
@@ -68,7 +81,7 @@ bool containsAtMostWarnings(Json::Value const& _compilerResult)
|
||||
{
|
||||
BOOST_REQUIRE(error.isObject());
|
||||
BOOST_REQUIRE(error["severity"].isString());
|
||||
if (error["severity"].asString() != "warning")
|
||||
if (langutil::Error::isError(str2Severity(error["severity"].asString())))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ void SyntaxTest::parseAndAnalyze()
|
||||
return error->type() == Error::Type::CodeGenerationError;
|
||||
});
|
||||
auto errorCount = count_if(errors.cbegin(), errors.cend(), [](auto const& error) {
|
||||
return error->type() != Error::Type::Warning;
|
||||
return Error::isError(error->type());
|
||||
});
|
||||
// failing compilation after successful analysis is a rare case,
|
||||
// it assumes that errors contain exactly one error, and the error is of type Error::Type::CodeGenerationError
|
||||
|
||||
Reference in New Issue
Block a user