mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Warn about using events without emit.
This commit is contained in:
parent
f58024b974
commit
8c1a8ecc2e
@ -961,7 +961,8 @@ void TypeChecker::endVisit(EmitStatement const& _emit)
|
||||
_emit.eventCall().annotation().kind != FunctionCallKind::FunctionCall ||
|
||||
dynamic_cast<FunctionType const&>(*type(_emit.eventCall().expression())).kind() != FunctionType::Kind::Event
|
||||
)
|
||||
m_errorReporter.typeError(_emit.eventCall().expression().location(), "Expression has to be an event.");
|
||||
m_errorReporter.typeError(_emit.eventCall().expression().location(), "Expression has to be an event invocation.");
|
||||
m_insideEmitStatement = false;
|
||||
}
|
||||
|
||||
bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
||||
@ -1540,6 +1541,13 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
||||
else if (functionName->name() == "suicide" && functionType->kind() == FunctionType::Kind::Selfdestruct)
|
||||
m_errorReporter.warning(_functionCall.location(), "\"suicide\" has been deprecated in favour of \"selfdestruct\"");
|
||||
}
|
||||
if (!m_insideEmitStatement && functionType->kind() == FunctionType::Kind::Event)
|
||||
{
|
||||
if (m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
|
||||
m_errorReporter.typeError(_functionCall.location(), "Event invocations have to be prefixed by \"emit\".");
|
||||
else
|
||||
m_errorReporter.warning(_functionCall.location(), "Invoking events without \"emit\" prefix is deprecated.");
|
||||
}
|
||||
|
||||
TypePointers parameterTypes = functionType->parameterTypes();
|
||||
|
||||
|
@ -94,6 +94,7 @@ private:
|
||||
virtual bool visit(WhileStatement const& _whileStatement) override;
|
||||
virtual bool visit(ForStatement const& _forStatement) override;
|
||||
virtual void endVisit(Return const& _return) override;
|
||||
virtual bool visit(EmitStatement const&) override { m_insideEmitStatement = true; return true; }
|
||||
virtual void endVisit(EmitStatement const& _emit) override;
|
||||
virtual bool visit(VariableDeclarationStatement const& _variable) override;
|
||||
virtual void endVisit(ExpressionStatement const& _statement) override;
|
||||
@ -131,6 +132,9 @@ private:
|
||||
|
||||
ContractDefinition const* m_scope = nullptr;
|
||||
|
||||
/// Flag indicating whether we are currently inside an EmitStatement.
|
||||
bool m_insideEmitStatement = false;
|
||||
|
||||
ErrorReporter& m_errorReporter;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user