diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-05 18:04:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-05 18:04:54 +0800 |
commit | 36d6c27e6826f173b491a7a536a3755609edaa29 (patch) | |
tree | 23e7cd9d859a3beb94d5d5cdaaa644f8c41ecf20 /libsolidity/ast | |
parent | c6da5c1650964f9dadd4b483d42585223e086b74 (diff) | |
parent | 8fdbd19a05c976908172d0f776a0f96837449683 (diff) | |
download | dexon-solidity-36d6c27e6826f173b491a7a536a3755609edaa29.tar dexon-solidity-36d6c27e6826f173b491a7a536a3755609edaa29.tar.gz dexon-solidity-36d6c27e6826f173b491a7a536a3755609edaa29.tar.bz2 dexon-solidity-36d6c27e6826f173b491a7a536a3755609edaa29.tar.lz dexon-solidity-36d6c27e6826f173b491a7a536a3755609edaa29.tar.xz dexon-solidity-36d6c27e6826f173b491a7a536a3755609edaa29.tar.zst dexon-solidity-36d6c27e6826f173b491a7a536a3755609edaa29.zip |
Merge pull request #3745 from ethereum/fixRecursion
Fix invalid recursion errors for structs
Diffstat (limited to 'libsolidity/ast')
-rw-r--r-- | libsolidity/ast/Types.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 42fd1c3d..ac1d3b01 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -28,6 +28,7 @@ #include <libdevcore/CommonData.h> #include <libdevcore/SHA3.h> #include <libdevcore/UTF8.h> +#include <libdevcore/Algorithms.h> #include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/replace.hpp> @@ -1971,25 +1972,19 @@ bool StructType::recursive() const { if (!m_recursive.is_initialized()) { - set<StructDefinition const*> structsSeen; - function<bool(StructType const*)> check = [&](StructType const* t) -> bool + auto visitor = [&](StructDefinition const& _struct, CycleDetector<StructDefinition>& _cycleDetector) { - StructDefinition const* str = &t->structDefinition(); - if (structsSeen.count(str)) - return true; - structsSeen.insert(str); - for (ASTPointer<VariableDeclaration> const& variable: str->members()) + for (ASTPointer<VariableDeclaration> const& variable: _struct.members()) { Type const* memberType = variable->annotation().type.get(); while (dynamic_cast<ArrayType const*>(memberType)) memberType = dynamic_cast<ArrayType const*>(memberType)->baseType().get(); if (StructType const* innerStruct = dynamic_cast<StructType const*>(memberType)) - if (check(innerStruct)) - return true; + if (_cycleDetector.run(innerStruct->structDefinition())) + return; } - return false; }; - m_recursive = check(this); + m_recursive = (CycleDetector<StructDefinition>(visitor).run(structDefinition()) != nullptr); } return *m_recursive; } |