Warn about using events without emit.

This commit is contained in:
chriseth 2018-02-16 17:32:41 +01:00
parent f58024b974
commit 8c1a8ecc2e
2 changed files with 13 additions and 1 deletions

View File

@ -961,7 +961,8 @@ void TypeChecker::endVisit(EmitStatement const& _emit)
_emit.eventCall().annotation().kind != FunctionCallKind::FunctionCall || _emit.eventCall().annotation().kind != FunctionCallKind::FunctionCall ||
dynamic_cast<FunctionType const&>(*type(_emit.eventCall().expression())).kind() != FunctionType::Kind::Event 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) 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) else if (functionName->name() == "suicide" && functionType->kind() == FunctionType::Kind::Selfdestruct)
m_errorReporter.warning(_functionCall.location(), "\"suicide\" has been deprecated in favour of \"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(); TypePointers parameterTypes = functionType->parameterTypes();

View File

@ -94,6 +94,7 @@ private:
virtual bool visit(WhileStatement const& _whileStatement) override; virtual bool visit(WhileStatement const& _whileStatement) override;
virtual bool visit(ForStatement const& _forStatement) override; virtual bool visit(ForStatement const& _forStatement) override;
virtual void endVisit(Return const& _return) 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 void endVisit(EmitStatement const& _emit) override;
virtual bool visit(VariableDeclarationStatement const& _variable) override; virtual bool visit(VariableDeclarationStatement const& _variable) override;
virtual void endVisit(ExpressionStatement const& _statement) override; virtual void endVisit(ExpressionStatement const& _statement) override;
@ -131,6 +132,9 @@ private:
ContractDefinition const* m_scope = nullptr; ContractDefinition const* m_scope = nullptr;
/// Flag indicating whether we are currently inside an EmitStatement.
bool m_insideEmitStatement = false;
ErrorReporter& m_errorReporter; ErrorReporter& m_errorReporter;
}; };