Merge pull request #9007 from a3d4/fix-8727-no-return-optimizer-error

Report an error if immutables not assigned
This commit is contained in:
chriseth
2020-07-23 16:50:42 +02:00
committed by GitHub
7 changed files with 48 additions and 8 deletions
+13 -1
View File
@@ -74,7 +74,19 @@ void SyntaxTest::parseAndAnalyze()
try
{
if (!compiler().compile())
BOOST_THROW_EXCEPTION(runtime_error("Compilation failed even though analysis was successful."));
{
ErrorList const& errors = compiler().errors();
auto codeGeneretionErrorCount = count_if(errors.cbegin(), errors.cend(), [](auto const& error) {
return error->type() == Error::Type::CodeGenerationError;
});
auto errorCount = count_if(errors.cbegin(), errors.cend(), [](auto const& error) {
return error->type() != Error::Type::Warning;
});
// 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
if (codeGeneretionErrorCount != 1 || errorCount != 1)
BOOST_THROW_EXCEPTION(runtime_error("Compilation failed even though analysis was successful."));
}
}
catch (UnimplementedFeatureError const& _e)
{
@@ -0,0 +1,13 @@
contract C {
uint immutable x;
constructor() {
x = 0;
while (true)
{}
}
function f() external view returns(uint) { return x; }
}
// ====
// optimize-yul: true
// ----
// CodeGenerationError 1284: Some immutables were read from but never assigned, possibly because of optimization.