mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Only warn about unused return in low-level functions.
This commit is contained in:
parent
cc6314cd01
commit
25a64c7f8f
@ -831,12 +831,21 @@ void TypeChecker::endVisit(ExpressionStatement const& _statement)
|
|||||||
if (!dynamic_cast<RationalNumberType const&>(*type(_statement.expression())).mobileType())
|
if (!dynamic_cast<RationalNumberType const&>(*type(_statement.expression())).mobileType())
|
||||||
typeError(_statement.expression().location(), "Invalid rational number.");
|
typeError(_statement.expression().location(), "Invalid rational number.");
|
||||||
|
|
||||||
bool unusedReturnValue = true;
|
if (auto call = dynamic_cast<FunctionCall const*>(&_statement.expression()))
|
||||||
if (auto t = dynamic_cast<TupleType const*>(type(_statement.expression()).get()))
|
{
|
||||||
if (t->components().empty())
|
if (auto callType = dynamic_cast<FunctionType const*>(type(call->expression()).get()))
|
||||||
unusedReturnValue = false;
|
{
|
||||||
if (unusedReturnValue)
|
using Location = FunctionType::Location;
|
||||||
warning(_statement.location(), "Unused return value.");
|
Location location = callType->location();
|
||||||
|
if (
|
||||||
|
location == Location::Bare ||
|
||||||
|
location == Location::BareCallCode ||
|
||||||
|
location == Location::BareDelegateCall ||
|
||||||
|
location == Location::Send
|
||||||
|
)
|
||||||
|
warning(_statement.location(), "Return value of low-level calls not used.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TypeChecker::visit(Conditional const& _conditional)
|
bool TypeChecker::visit(Conditional const& _conditional)
|
||||||
|
@ -3760,7 +3760,7 @@ BOOST_AUTO_TEST_CASE(unused_return_value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
|
BOOST_CHECK(success(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(unused_return_value_send)
|
BOOST_AUTO_TEST_CASE(unused_return_value_send)
|
||||||
@ -3775,6 +3775,54 @@ BOOST_AUTO_TEST_CASE(unused_return_value_send)
|
|||||||
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
|
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(unused_return_value_call)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function f() {
|
||||||
|
address(0x12).call("abc");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(unused_return_value_call_value)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function f() {
|
||||||
|
address(0x12).call.value(2)("abc");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(unused_return_value_callcode)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function f() {
|
||||||
|
address(0x12).callcode("abc");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(unused_return_value_delegatecall)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function f() {
|
||||||
|
address(0x12).delegatecall("abc");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user