Browse Source

Merge pull request #2321 from chriseth/sol_memoryArraysNotResizeable

Memory arrays cannot be resized.
cl-refactor
Gav Wood 10 years ago
parent
commit
329dd6c338
  1. 7
      libsolidity/AST.cpp
  2. 13
      test/libsolidity/SolidityNameAndTypeResolution.cpp

7
libsolidity/AST.cpp

@ -936,8 +936,11 @@ void MemberAccess::checkTypeRequirements(TypePointers const* _argumentTypes)
else if (type.getCategory() == Type::Category::Array)
{
auto const& arrayType(dynamic_cast<ArrayType const&>(type));
m_isLValue = (*m_memberName == "length" &&
arrayType.location() != DataLocation::CallData && arrayType.isDynamicallySized());
m_isLValue = (
*m_memberName == "length" &&
arrayType.location() == DataLocation::Storage &&
arrayType.isDynamicallySized()
);
}
else
m_isLValue = false;

13
test/libsolidity/SolidityNameAndTypeResolution.cpp

@ -2026,6 +2026,19 @@ BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible)
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_CASE(memory_arrays_not_resizeable)
{
char const* sourceCode = R"(
contract C {
function f() {
uint[] memory x;
x.length = 2;
}
}
)";
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_SUITE_END()
}

Loading…
Cancel
Save