Deprecate throw.

This commit is contained in:
chriseth 2017-07-05 19:45:12 +02:00
parent 4bde6fa961
commit 0400e61e28
4 changed files with 27 additions and 1 deletions

View File

@ -1,11 +1,12 @@
### 0.4.13 (unreleased) ### 0.4.13 (unreleased)
Features: Features:
* Syntax Checker: Deprecated "throw" in favour of require(), assert() and revert().
* Type Checker: Warn if a local storage reference variable does not explicitly use the keyword ``storage``. * Type Checker: Warn if a local storage reference variable does not explicitly use the keyword ``storage``.
Bugfixes: Bugfixes:
* Compiler Interface: Only output AST if analysis was successful.
* Code Generator: Correctly unregister modifier variables. * Code Generator: Correctly unregister modifier variables.
* Compiler Interface: Only output AST if analysis was successful.
* Error Output: Do not omit the error type. * Error Output: Do not omit the error type.
### 0.4.12 (2017-07-03) ### 0.4.12 (2017-07-03)

View File

@ -135,6 +135,16 @@ bool SyntaxChecker::visit(Break const& _breakStatement)
return true; return true;
} }
bool SyntaxChecker::visit(Throw const& _throwStatement)
{
m_errorReporter.warning(
_throwStatement.location(),
"\"throw\" is deprecated in favour of \"revert()\", \"require()\" and \"assert()\"."
);
return true;
}
bool SyntaxChecker::visit(UnaryOperation const& _operation) bool SyntaxChecker::visit(UnaryOperation const& _operation)
{ {
if (_operation.getOperator() == Token::Add) if (_operation.getOperator() == Token::Add)

View File

@ -33,6 +33,7 @@ namespace solidity
* - whether continue/break is in a for/while loop. * - whether continue/break is in a for/while loop.
* - whether a modifier contains at least one '_' * - whether a modifier contains at least one '_'
* - issues deprecation warnings for unary '+' * - issues deprecation warnings for unary '+'
* - issues deprecation warning for throw
*/ */
class SyntaxChecker: private ASTConstVisitor class SyntaxChecker: private ASTConstVisitor
{ {
@ -59,6 +60,8 @@ private:
virtual bool visit(Continue const& _continueStatement) override; virtual bool visit(Continue const& _continueStatement) override;
virtual bool visit(Break const& _breakStatement) override; virtual bool visit(Break const& _breakStatement) override;
virtual bool visit(Throw const& _throwStatement) override;
virtual bool visit(UnaryOperation const& _operation) override; virtual bool visit(UnaryOperation const& _operation) override;
virtual bool visit(PlaceholderStatement const& _placeholderStatement) override; virtual bool visit(PlaceholderStatement const& _placeholderStatement) override;

View File

@ -5860,6 +5860,18 @@ BOOST_AUTO_TEST_CASE(using_interface_complex)
success(text); success(text);
} }
BOOST_AUTO_TEST_CASE(warn_about_throw)
{
char const* text = R"(
contract C {
function f() {
throw;
}
}
)";
CHECK_WARNING(text, "\"throw\" is deprecated");
}
BOOST_AUTO_TEST_CASE(bare_revert) BOOST_AUTO_TEST_CASE(bare_revert)
{ {
char const* text = R"( char const* text = R"(