Skip to content

Commit

Permalink
Turn deprecated warnings for sha3/suicide into errors (experimental 0…
Browse files Browse the repository at this point in the history
….5.0)
  • Loading branch information
axic committed Apr 20, 2018
1 parent edd20eb commit 0493e3b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 10 additions & 2 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,10 +1652,18 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)

if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression()))
{
string msg;
if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3)
m_errorReporter.warning(_functionCall.location(), "\"sha3\" has been deprecated in favour of \"keccak256\"");
msg = "\"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\"");
msg = "\"suicide\" has been deprecated in favour of \"selfdestruct\"";
if (!msg.empty())
{
if (v050)
m_errorReporter.typeError(_functionCall.location(), msg);
else
m_errorReporter.warning(_functionCall.location(), msg);
}
}
if (!m_insideEmitStatement && functionType->kind() == FunctionType::Kind::Event)
{
Expand Down
13 changes: 13 additions & 0 deletions test/libsolidity/syntaxTests/deprecated_functions_050.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
bytes32 x = sha3(uint8(1));
x;
}
function g() public {
suicide(1);
}
}
// ----
// TypeError: (88-102): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (137-147): "suicide" has been deprecated in favour of "selfdestruct"
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract C {

// ----
// TypeError: (117-118): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
// Warning: (191-198): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (191-198): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (196-197): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
// TypeError: (277-278): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
// TypeError: (361-362): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
Expand Down

0 comments on commit 0493e3b

Please sign in to comment.