aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-03-16 02:07:25 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-03 22:27:28 +0800
commit5bdadff0d8a9c32745dd46aa639283718613efdc (patch)
treee7661ff74a4620669381041a2f4c719d5abaa77f
parentc42caedec2b6dc2bfb268f538eecb1d4ee18f9d8 (diff)
downloaddexon-solidity-5bdadff0d8a9c32745dd46aa639283718613efdc.tar.gz
dexon-solidity-5bdadff0d8a9c32745dd46aa639283718613efdc.tar.zst
dexon-solidity-5bdadff0d8a9c32745dd46aa639283718613efdc.zip
Fix detection of recursive structs.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/ast/Types.cpp5
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol15
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol15
4 files changed, 36 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index 70e98751..63c99144 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -16,6 +16,7 @@ Bugfixes:
* Commandline interface: Support ``--evm-version constantinople`` properly.
* DocString Parser: Fix error message for empty descriptions.
* Standard JSON: Support ``constantinople`` as ``evmVersion`` properly.
+ * Type Checker: Fix detection of recursive structs.
* Type System: Improve error message when attempting to shift by a fractional amount.
* Type System: Make external library functions accessible.
* Type System: Prevent encoding of weird types.
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 42fd1c3d..42f6b5ca 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -1972,9 +1972,12 @@ bool StructType::recursive() const
if (!m_recursive.is_initialized())
{
set<StructDefinition const*> structsSeen;
+ set<StructDefinition const*> structsProcessed;
function<bool(StructType const*)> check = [&](StructType const* t) -> bool
{
StructDefinition const* str = &t->structDefinition();
+ if (structsProcessed.count(str))
+ return false;
if (structsSeen.count(str))
return true;
structsSeen.insert(str);
@@ -1987,6 +1990,8 @@ bool StructType::recursive() const
if (check(innerStruct))
return true;
}
+ structsSeen.erase(str);
+ structsProcessed.insert(str);
return false;
};
m_recursive = check(this);
diff --git a/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol
new file mode 100644
index 00000000..9a1c22f1
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol
@@ -0,0 +1,15 @@
+pragma experimental ABIEncoderV2;
+
+contract C {
+ struct T { U u; V v; }
+
+ struct U { W w; }
+
+ struct V { W w; }
+
+ struct W { uint x; }
+
+ function f(T) public pure { }
+}
+// ----
+// Warning: Experimental features are turned on. Do not use experimental features on live deployments.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol
new file mode 100644
index 00000000..d4ad088d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol
@@ -0,0 +1,15 @@
+pragma experimental ABIEncoderV2;
+
+contract TestContract
+{
+ struct SubStruct {
+ uint256 id;
+ }
+ struct TestStruct {
+ SubStruct subStruct1;
+ SubStruct subStruct2;
+ }
+ function addTestStruct(TestStruct) public pure {}
+}
+// ----
+// Warning: Experimental features are turned on. Do not use experimental features on live deployments.