mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow immutable initialization in try catch statements
Trigger github
This commit is contained in:
@@ -132,6 +132,19 @@ bool ImmutableValidator::visit(WhileStatement const& _whileStatement)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImmutableValidator::visit(TryStatement const& _tryStatement)
|
||||
{
|
||||
ScopedSaveAndRestore constructorGuard{m_inTryStatement, true};
|
||||
|
||||
_tryStatement.externalCall().accept(*this);
|
||||
|
||||
for (auto&& clause: _tryStatement.clauses())
|
||||
if (clause)
|
||||
clause->accept(*this);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ImmutableValidator::endVisit(IdentifierPath const& _identifierPath)
|
||||
{
|
||||
if (auto const callableDef = dynamic_cast<CallableDeclaration const*>(_identifierPath.annotation().referencedDeclaration))
|
||||
@@ -217,6 +230,12 @@ void ImmutableValidator::analyseVariableReference(VariableDeclaration const& _va
|
||||
_expression.location(),
|
||||
"Cannot write to immutable here: Immutable variables cannot be initialized inside an if statement."
|
||||
);
|
||||
else if (m_inTryStatement)
|
||||
m_errorReporter.typeError(
|
||||
4130_error,
|
||||
_expression.location(),
|
||||
"Cannot write to immutable here: Immutable variables cannot be initialized inside a try/catch statement."
|
||||
);
|
||||
else if (m_initializedStateVariables.count(&_variableReference))
|
||||
{
|
||||
if (!read)
|
||||
|
||||
@@ -55,6 +55,7 @@ private:
|
||||
bool visit(MemberAccess const& _memberAccess);
|
||||
bool visit(IfStatement const& _ifStatement);
|
||||
bool visit(WhileStatement const& _whileStatement);
|
||||
bool visit(TryStatement const& _tryStatement);
|
||||
void endVisit(IdentifierPath const& _identifierPath);
|
||||
void endVisit(Identifier const& _identifier);
|
||||
void endVisit(Return const& _return);
|
||||
@@ -78,6 +79,7 @@ private:
|
||||
bool m_inLoop = false;
|
||||
bool m_inBranch = false;
|
||||
bool m_inCreationContext = true;
|
||||
bool m_inTryStatement = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user