diff options
author | chriseth <chris@ethereum.org> | 2017-09-21 00:00:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-21 00:00:40 +0800 |
commit | 8af298ade31ed1337ec20bf50cdb963bbd50c0db (patch) | |
tree | 172da56472b55194199bc310fe36ab6f1be9cd22 | |
parent | 2adeb26d4396d94b322aeeef98bfb679a7cbce27 (diff) | |
parent | ed1fd49ab07de1ddad9f3bc2864e17fe21ed993d (diff) | |
download | dexon-solidity-8af298ade31ed1337ec20bf50cdb963bbd50c0db.tar dexon-solidity-8af298ade31ed1337ec20bf50cdb963bbd50c0db.tar.gz dexon-solidity-8af298ade31ed1337ec20bf50cdb963bbd50c0db.tar.bz2 dexon-solidity-8af298ade31ed1337ec20bf50cdb963bbd50c0db.tar.lz dexon-solidity-8af298ade31ed1337ec20bf50cdb963bbd50c0db.tar.xz dexon-solidity-8af298ade31ed1337ec20bf50cdb963bbd50c0db.tar.zst dexon-solidity-8af298ade31ed1337ec20bf50cdb963bbd50c0db.zip |
Merge pull request #2902 from ethereum/warn-obsolete
Warn about obsolete sha3/suicide calls
-rw-r--r-- | Changelog.md | 4 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 29 |
3 files changed, 38 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 9c623805..458a9543 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,7 +6,9 @@ Features: * Code Generator: Added ``.selector`` member on external function types to retrieve their signature. * Code Generator: Keep a single copy of encoding functions when using the experimental "ABIEncoderV2". * Optimizer: Add new optimization step to remove unused ``JUMPDEST``s. - * Code Generator: Support passing ``structs`` as arguments and return parameters (requires ``pragma experimental ABIEncoderV2`` for now). + * Code Generator: Support passing ``structs`` as arguments and return parameters (requires ``pragma experimental ABIEncoderV2;`` for now). + * Static Analyzer: Warn for using deprecated builtins ``sha3`` and ``suicide`` + (replaced by ``keccak256`` and ``selfdestruct``, introduced in 0.4.2 and 0.2.0, respectively). * Syntax Checker: Warn if no visibility is specified on contract functions. * Type Checker: Display helpful warning for unused function arguments/return parameters. * Type Checker: Do not show the same error multiple times for events. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 40add37e..4b2ec8d6 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1477,6 +1477,14 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) else _functionCall.annotation().type = make_shared<TupleType>(functionType->returnParameterTypes()); + if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression())) + { + if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3) + m_errorReporter.warning(_functionCall.location(), "\"sha3\" has been deprecated in favour of \"keccak256\""); + else if (functionName->name() == "suicide" && functionType->kind() == FunctionType::Kind::Selfdestruct) + m_errorReporter.warning(_functionCall.location(), "\"suicide\" has been deprecated in favour of \"selfdestruct\""); + } + TypePointers parameterTypes = functionType->parameterTypes(); if (!functionType->padArguments()) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 2ca3a562..39c47f9c 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -4679,7 +4679,7 @@ BOOST_AUTO_TEST_CASE(warn_about_callcode) } } )"; - CHECK_WARNING(text, "\"callcode\" has been deprecated in favour"); + CHECK_WARNING(text, "\"callcode\" has been deprecated in favour of \"delegatecall\""); } BOOST_AUTO_TEST_CASE(no_warn_about_callcode_as_function) @@ -6877,7 +6877,7 @@ BOOST_AUTO_TEST_CASE(tight_packing_literals) } } )"; - CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8."); +// CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8."); text = R"( contract C { function f() pure public returns (bytes32) { @@ -6928,6 +6928,31 @@ BOOST_AUTO_TEST_CASE(non_external_fallback) CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\"."); } +BOOST_AUTO_TEST_CASE(warn_about_sha3) +{ + char const* text = R"( + contract test { + function f() pure public { + var x = sha3(uint8(1)); + x; + } + } + )"; + CHECK_WARNING(text, "\"sha3\" has been deprecated in favour of \"keccak256\""); +} + +BOOST_AUTO_TEST_CASE(warn_about_suicide) +{ + char const* text = R"( + contract test { + function f() public { + suicide(1); + } + } + )"; + CHECK_WARNING(text, "\"suicide\" has been deprecated in favour of \"selfdestruct\""); +} + BOOST_AUTO_TEST_SUITE_END() } |