aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-07-16 07:06:19 +0800
committerchriseth <c@ethdev.com>2015-07-16 07:10:09 +0800
commit13effae9d3247ff29f91310b18367fdb5920736d (patch)
tree1a035bb5b8016741207166873620f8def3bd6ab0
parent6be070cf1f9e620995aaff7774669dd3f9f8fa90 (diff)
downloaddexon-solidity-13effae9d3247ff29f91310b18367fdb5920736d.tar.gz
dexon-solidity-13effae9d3247ff29f91310b18367fdb5920736d.tar.zst
dexon-solidity-13effae9d3247ff29f91310b18367fdb5920736d.zip
Allow structs containing mappings in memory.
-rw-r--r--libsolidity/SolidityEndToEndTest.cpp23
-rw-r--r--libsolidity/SolidityNameAndTypeResolution.cpp15
2 files changed, 38 insertions, 0 deletions
diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp
index 9f806347..b5c78656 100644
--- a/libsolidity/SolidityEndToEndTest.cpp
+++ b/libsolidity/SolidityEndToEndTest.cpp
@@ -5034,6 +5034,29 @@ BOOST_AUTO_TEST_CASE(literal_strings)
}
+BOOST_AUTO_TEST_CASE(memory_structs_with_mappings)
+{
+ char const* sourceCode = R"(
+ contract Test {
+ struct S { uint8 a; mapping(uint => uint) b; uint8 c; }
+ S s;
+ function f() returns (uint) {
+ S memory x;
+ if (x.a != 0 || x.c != 0) return 1;
+ x.a = 4; x.c = 5;
+ s = x;
+ if (s.a != 4 || s.c != 5) return 2;
+ x = S(2, 3);
+ if (x.a != 2 || x.c != 3) return 3;
+ x = s;
+ if (s.a != 4 || s.c != 5) return 4;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Test");
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp
index 0f5e4800..cfc43df9 100644
--- a/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2134,6 +2134,21 @@ BOOST_AUTO_TEST_CASE(invalid_integer_literal_exp)
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
}
+BOOST_AUTO_TEST_CASE(memory_structs_with_mappings)
+{
+ char const* text = R"(
+ contract Test {
+ struct S { uint8 a; mapping(uint => uint) b; uint8 c; }
+ S s;
+ function f() {
+ S memory x;
+ x.b[1];
+ }
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}