mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Delete for memory objects.
This commit is contained in:
parent
65d89bde6d
commit
7100b14d4d
@ -4691,6 +4691,35 @@ BOOST_AUTO_TEST_CASE(memory_types_initialisation)
|
|||||||
BOOST_CHECK(callContractFunction("nestedStat()") == encodeArgs(vector<u256>(3 * 7)));
|
BOOST_CHECK(callContractFunction("nestedStat()") == encodeArgs(vector<u256>(3 * 7)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(memory_arrays_delete)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract Test {
|
||||||
|
function del() returns (uint24[3][4]) {
|
||||||
|
uint24[3][4] memory x;
|
||||||
|
for (uint24 i = 0; i < x.length; i ++)
|
||||||
|
for (uint24 j = 0; j < x[i].length; j ++)
|
||||||
|
x[i][j] = i * 0x10 + j;
|
||||||
|
delete x[1];
|
||||||
|
delete x[3][2];
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "Test");
|
||||||
|
|
||||||
|
vector<u256> data(3 * 4);
|
||||||
|
for (unsigned i = 0; i < 4; i++)
|
||||||
|
for (unsigned j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
u256 v = 0;
|
||||||
|
if (!(i == 1 || (i == 3 && j == 2)))
|
||||||
|
v = i * 0x10 + j;
|
||||||
|
data[i * 3 + j] = v;
|
||||||
|
}
|
||||||
|
BOOST_CHECK(callContractFunction("del()") == encodeArgs(data));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write)
|
BOOST_AUTO_TEST_CASE(memory_arrays_index_access_write)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
@ -1900,6 +1900,18 @@ BOOST_AUTO_TEST_CASE(storage_location_local_variables)
|
|||||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
|
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(no_mappings_in_memory_array)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract C {
|
||||||
|
function f() {
|
||||||
|
mapping(uint=>uint)[] memory x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(assignment_mem_to_local_storage_variable)
|
BOOST_AUTO_TEST_CASE(assignment_mem_to_local_storage_variable)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
@ -1931,6 +1943,20 @@ BOOST_AUTO_TEST_CASE(storage_assign_to_different_local_variable)
|
|||||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(no_delete_on_storage_pointers)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract C {
|
||||||
|
uint[] data;
|
||||||
|
function f() {
|
||||||
|
var x = data;
|
||||||
|
delete x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(assignment_mem_storage_variable_directly)
|
BOOST_AUTO_TEST_CASE(assignment_mem_storage_variable_directly)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user