Skip to content

Commit eca2655

Browse files
authored
Merge pull request #2529 from ethereum/warnThrow
Deprecate throw.
2 parents 4bde6fa + 0400e61 commit eca2655

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
### 0.4.13 (unreleased)
22

33
Features:
4+
* Syntax Checker: Deprecated "throw" in favour of require(), assert() and revert().
45
* Type Checker: Warn if a local storage reference variable does not explicitly use the keyword ``storage``.
56

67
Bugfixes:
7-
* Compiler Interface: Only output AST if analysis was successful.
88
* Code Generator: Correctly unregister modifier variables.
9+
* Compiler Interface: Only output AST if analysis was successful.
910
* Error Output: Do not omit the error type.
1011

1112
### 0.4.12 (2017-07-03)

libsolidity/analysis/SyntaxChecker.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ bool SyntaxChecker::visit(Break const& _breakStatement)
135135
return true;
136136
}
137137

138+
bool SyntaxChecker::visit(Throw const& _throwStatement)
139+
{
140+
m_errorReporter.warning(
141+
_throwStatement.location(),
142+
"\"throw\" is deprecated in favour of \"revert()\", \"require()\" and \"assert()\"."
143+
);
144+
145+
return true;
146+
}
147+
138148
bool SyntaxChecker::visit(UnaryOperation const& _operation)
139149
{
140150
if (_operation.getOperator() == Token::Add)

libsolidity/analysis/SyntaxChecker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace solidity
3333
* - whether continue/break is in a for/while loop.
3434
* - whether a modifier contains at least one '_'
3535
* - issues deprecation warnings for unary '+'
36+
* - issues deprecation warning for throw
3637
*/
3738
class SyntaxChecker: private ASTConstVisitor
3839
{
@@ -59,6 +60,8 @@ class SyntaxChecker: private ASTConstVisitor
5960
virtual bool visit(Continue const& _continueStatement) override;
6061
virtual bool visit(Break const& _breakStatement) override;
6162

63+
virtual bool visit(Throw const& _throwStatement) override;
64+
6265
virtual bool visit(UnaryOperation const& _operation) override;
6366

6467
virtual bool visit(PlaceholderStatement const& _placeholderStatement) override;

test/libsolidity/SolidityNameAndTypeResolution.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5860,6 +5860,18 @@ BOOST_AUTO_TEST_CASE(using_interface_complex)
58605860
success(text);
58615861
}
58625862

5863+
BOOST_AUTO_TEST_CASE(warn_about_throw)
5864+
{
5865+
char const* text = R"(
5866+
contract C {
5867+
function f() {
5868+
throw;
5869+
}
5870+
}
5871+
)";
5872+
CHECK_WARNING(text, "\"throw\" is deprecated");
5873+
}
5874+
58635875
BOOST_AUTO_TEST_CASE(bare_revert)
58645876
{
58655877
char const* text = R"(

0 commit comments

Comments
 (0)