mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9007 from a3d4/fix-8727-no-return-optimizer-error
Report an error if immutables not assigned
This commit is contained in:
@@ -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.
|
||||
Reference in New Issue
Block a user