aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Gluhovsky <gluk256@gmail.com>2015-06-16 20:43:30 +0800
committerVlad Gluhovsky <gluk256@gmail.com>2015-06-16 20:43:30 +0800
commit1e91ea0b3929331a07059751943e3620901a51f8 (patch)
tree3a50e85e926efd870b6bd1d00f0fc06d562ed5b6
parent7cb9b566b7286b9a42d18fe3c93cbbc16c14199f (diff)
parentfd745418438f24991eed33a96da6724feb22b824 (diff)
downloaddexon-solidity-1e91ea0b3929331a07059751943e3620901a51f8.tar
dexon-solidity-1e91ea0b3929331a07059751943e3620901a51f8.tar.gz
dexon-solidity-1e91ea0b3929331a07059751943e3620901a51f8.tar.bz2
dexon-solidity-1e91ea0b3929331a07059751943e3620901a51f8.tar.lz
dexon-solidity-1e91ea0b3929331a07059751943e3620901a51f8.tar.xz
dexon-solidity-1e91ea0b3929331a07059751943e3620901a51f8.tar.zst
dexon-solidity-1e91ea0b3929331a07059751943e3620901a51f8.zip
Merge branch 'develop' of https://github.com/ethereum/cpp-ethereum into develop
-rw-r--r--libsolidity/SolidityNameAndTypeResolution.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp
index 3948a4a2..fced1284 100644
--- a/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -1889,6 +1889,93 @@ BOOST_AUTO_TEST_CASE(storage_location_local_variables)
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
}
+BOOST_AUTO_TEST_CASE(assignment_mem_to_local_storage_variable)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint[] data;
+ function f(uint[] x) {
+ var dataRef = data;
+ dataRef = x;
+ }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(storage_assign_to_different_local_variable)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint[] data;
+ uint8[] otherData;
+ function f() {
+ uint8[] storage x = otherData;
+ uint[] storage y = data;
+ y = x;
+ // note that data = otherData works
+ }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(assignment_mem_storage_variable_directly)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint[] data;
+ function f(uint[] x) {
+ data = x;
+ }
+ }
+ )";
+ BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
+}
+
+BOOST_AUTO_TEST_CASE(function_argument_mem_to_storage)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint[] storage x) private {
+ }
+ function g(uint[] x) {
+ f(x);
+ }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(function_argument_storage_to_mem)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint[] storage x) private {
+ g(x);
+ }
+ function g(uint[] x) {
+ }
+ }
+ )";
+ BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
+}
+
+BOOST_AUTO_TEST_CASE(mem_array_assignment_changes_base_type)
+{
+ // Such an assignment is possible in storage, but not in memory
+ // (because it would incur an otherwise unnecessary copy).
+ // This requirement might be lifted, though.
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint8[] memory x) private {
+ uint[] memory y = x;
+ }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}