Merge pull request #11606 from ethereum/info_message

Add new info severity
This commit is contained in:
Leonardo
2021-09-14 14:30:07 +02:00
committed by GitHub
38 changed files with 191 additions and 97 deletions
+6 -6
View File
@@ -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;
}
+2 -2
View File
@@ -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"};
+4 -4
View File
@@ -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()))
+1 -1
View File
@@ -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";
+1 -1
View File
@@ -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;
}
+14 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -200,7 +200,7 @@ TestCase::TestResult ControlFlowGraphTest::run(ostream& _stream, string const& _
{
ErrorList errors;
auto [object, analysisInfo] = parse(m_source, *m_dialect, errors);
if (!object || !analysisInfo || !Error::containsOnlyWarnings(errors))
if (!object || !analysisInfo || Error::containsErrors(errors))
{
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
return TestResult::FatalError;
+7 -7
View File
@@ -72,7 +72,7 @@ pair<bool, ErrorList> parse(string const& _source)
return {false, {}};
}
optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarnings = true)
optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarningsAndInfos = true)
{
bool success;
ErrorList errors;
@@ -85,11 +85,11 @@ optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarni
else
{
// If success is true, there might still be an error in the assembly stage.
if (_allowWarnings && Error::containsOnlyWarnings(errors))
if (_allowWarningsAndInfos && !Error::containsErrors(errors))
return {};
else if (!errors.empty())
{
if (!_allowWarnings)
if (!_allowWarningsAndInfos)
BOOST_CHECK_EQUAL(errors.size(), 1);
return *errors.front();
}
@@ -97,15 +97,15 @@ optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarni
return {};
}
bool successParse(string const& _source, bool _allowWarnings = true)
bool successParse(string const& _source, bool _allowWarningsAndInfos = true)
{
return !parseAndReturnFirstError(_source, _allowWarnings);
return !parseAndReturnFirstError(_source, _allowWarningsAndInfos);
}
Error expectError(string const& _source, bool _allowWarnings = false)
Error expectError(string const& _source, bool _allowWarningsAndInfos = false)
{
auto error = parseAndReturnFirstError(_source, _allowWarnings);
auto error = parseAndReturnFirstError(_source, _allowWarningsAndInfos);
BOOST_REQUIRE(error);
return *error;
}
+7 -7
View File
@@ -85,7 +85,7 @@ shared_ptr<Block> parse(string const& _source, Dialect const& _dialect, ErrorRep
return {};
}
std::optional<Error> parseAndReturnFirstError(string const& _source, Dialect const& _dialect, bool _allowWarnings = true)
std::optional<Error> parseAndReturnFirstError(string const& _source, Dialect const& _dialect, bool _allowWarningsAndInfos = true)
{
ErrorList errors;
ErrorReporter errorReporter(errors);
@@ -98,11 +98,11 @@ std::optional<Error> parseAndReturnFirstError(string const& _source, Dialect con
else
{
// If success is true, there might still be an error in the assembly stage.
if (_allowWarnings && Error::containsOnlyWarnings(errors))
if (_allowWarningsAndInfos && !Error::containsErrors(errors))
return {};
else if (!errors.empty())
{
if (!_allowWarnings)
if (!_allowWarningsAndInfos)
BOOST_CHECK_EQUAL(errors.size(), 1);
return *errors.front();
}
@@ -110,15 +110,15 @@ std::optional<Error> parseAndReturnFirstError(string const& _source, Dialect con
return {};
}
bool successParse(std::string const& _source, Dialect const& _dialect = Dialect::yulDeprecated(), bool _allowWarnings = true)
bool successParse(std::string const& _source, Dialect const& _dialect = Dialect::yulDeprecated(), bool _allowWarningsAndInfos = true)
{
return !parseAndReturnFirstError(_source, _dialect, _allowWarnings);
return !parseAndReturnFirstError(_source, _dialect, _allowWarningsAndInfos);
}
Error expectError(std::string const& _source, Dialect const& _dialect = Dialect::yulDeprecated(), bool _allowWarnings = false)
Error expectError(std::string const& _source, Dialect const& _dialect = Dialect::yulDeprecated(), bool _allowWarningsAndInfos = false)
{
auto error = parseAndReturnFirstError(_source, _dialect, _allowWarnings);
auto error = parseAndReturnFirstError(_source, _dialect, _allowWarningsAndInfos);
BOOST_REQUIRE(error);
return *error;
}
+1 -1
View File
@@ -217,7 +217,7 @@ TestCase::TestResult StackLayoutGeneratorTest::run(ostream& _stream, string cons
{
ErrorList errors;
auto [object, analysisInfo] = parse(m_source, *m_dialect, errors);
if (!object || !analysisInfo || !Error::containsOnlyWarnings(errors))
if (!object || !analysisInfo || Error::containsErrors(errors))
{
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
return TestResult::FatalError;
+1 -1
View File
@@ -114,7 +114,7 @@ std::pair<std::shared_ptr<Object>, std::shared_ptr<AsmAnalysisInfo>> YulOptimize
shared_ptr<Object> object;
shared_ptr<AsmAnalysisInfo> analysisInfo;
std::tie(object, analysisInfo) = yul::test::parse(_source, *m_dialect, errors);
if (!object || !analysisInfo || !Error::containsOnlyWarnings(errors))
if (!object || !analysisInfo || Error::containsErrors(errors))
{
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
CharStream charStream(_source, "");
+1 -1
View File
@@ -29,7 +29,7 @@ bytes YulAssembler::assemble()
!m_stack.parseAndAnalyze("source", m_yulProgram) ||
!m_stack.parserResult()->code ||
!m_stack.parserResult()->analysisInfo ||
!langutil::Error::containsOnlyWarnings(m_stack.errors())
langutil::Error::containsErrors(m_stack.errors())
)
yulAssert(false, "Yul program could not be parsed successfully.");
+1 -1
View File
@@ -72,7 +72,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
!stack.parseAndAnalyze("source", yul_source) ||
!stack.parserResult()->code ||
!stack.parserResult()->analysisInfo ||
!Error::containsOnlyWarnings(stack.errors())
Error::containsErrors(stack.errors())
)
yulAssert(false, "Proto fuzzer generated malformed program");
+1 -1
View File
@@ -71,7 +71,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
!stack.parseAndAnalyze("source", yul_source) ||
!stack.parserResult()->code ||
!stack.parserResult()->analysisInfo ||
!Error::containsOnlyWarnings(stack.errors())
Error::containsErrors(stack.errors())
)
{
SourceReferenceFormatter formatter(std::cout, stack, false, false);