Skip to content

Commit d30b046

Browse files
committed
Add resolveUnaryTuples helper.
1 parent 9542e46 commit d30b046

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

libsolidity/analysis/ControlFlowBuilder.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// SPDX-License-Identifier: GPL-3.0
1818

1919
#include <libsolidity/analysis/ControlFlowBuilder.h>
20+
#include <libsolidity/ast/ASTUtils.h>
2021
#include <libyul/AST.h>
2122
#include <libyul/backends/evm/EVMDialect.h>
2223

@@ -617,11 +618,7 @@ bool ControlFlowBuilder::visit(VariableDeclarationStatement const& _variableDecl
617618
solAssert(tupleExpression->components().size() > i, "");
618619
expression = tupleExpression->components()[i].get();
619620
}
620-
while (auto tupleExpression = dynamic_cast<TupleExpression const*>(expression))
621-
if (tupleExpression->components().size() == 1)
622-
expression = tupleExpression->components().front().get();
623-
else
624-
break;
621+
expression = resolveUnaryTuples(expression);
625622
m_currentNode->variableOccurrences.emplace_back(
626623
*var,
627624
VariableOccurrence::Kind::Assignment,

libsolidity/ast/ASTUtils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,14 @@ VariableDeclaration const* rootConstVariableDeclaration(VariableDeclaration cons
8585
return rootDecl;
8686
}
8787

88+
Expression const* resolveUnaryTuples(Expression const* _expr)
89+
{
90+
while (auto const* tupleExpression = dynamic_cast<TupleExpression const*>(_expr))
91+
if (tupleExpression->components().size() == 1)
92+
_expr = tupleExpression->components().front().get();
93+
else
94+
break;
95+
return _expr;
96+
}
97+
8898
}

libsolidity/ast/ASTUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ bool isConstantVariableRecursive(VariableDeclaration const& _varDecl);
3838
/// Returns the innermost AST node that covers the given location or nullptr if not found.
3939
ASTNode const* locateInnermostASTNode(int _offsetInFile, SourceUnit const& _sourceUnit);
4040

41+
/// @returns @a _expr itself, in case it is not an unary tuple expression. Otherwise it descends recursively
42+
/// into unary tuples and returns the contained expression.
43+
Expression const* resolveUnaryTuples(Expression const* _expr);
44+
4145
}

0 commit comments

Comments
 (0)