Warn about copies in storage that might overwrite unexpectedly.

This commit is contained in:
chriseth
2017-06-26 16:31:36 +02:00
parent 751ba701bc
commit d0b6de0b34
4 changed files with 77 additions and 0 deletions
@@ -5771,6 +5771,48 @@ BOOST_AUTO_TEST_CASE(pure_statement_check_for_regular_for_loop)
success(text);
}
BOOST_AUTO_TEST_CASE(warn_multiple_storage_storage_copies)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() {
(x, y) = (y, x);
}
}
)";
CHECK_WARNING(text, "This assignment performs two copies to storage.");
}
BOOST_AUTO_TEST_CASE(warn_multiple_storage_storage_copies_fill_right)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() {
(x, y, ) = (y, x, 1, 2);
}
}
)";
CHECK_WARNING(text, "This assignment performs two copies to storage.");
}
BOOST_AUTO_TEST_CASE(warn_multiple_storage_storage_copies_fill_left)
{
char const* text = R"(
contract C {
struct S { uint a; uint b; }
S x; S y;
function f() {
(,x, y) = (1, 2, y, x);
}
}
)";
CHECK_WARNING(text, "This assignment performs two copies to storage.");
}
BOOST_AUTO_TEST_CASE(warn_unused_local)
{
char const* text = R"(