Skip to content

Commit e2602fb

Browse files
authored
Merge pull request github#14119 from github/alexdenisov/sequence-expr
Swift: fix SequenceExpr extraction
2 parents 7d89028 + 888dd78 commit e2602fb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

swift/extractor/translators/ExprTranslator.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,17 @@ codeql::UnresolvedMemberExpr ExprTranslator::translateUnresolvedMemberExpr(
460460

461461
codeql::SequenceExpr ExprTranslator::translateSequenceExpr(const swift::SequenceExpr& expr) {
462462
auto entry = createExprEntry(expr);
463-
entry.elements = dispatcher.fetchRepeatedLabels(expr.getElements());
463+
// SequenceExpr represents a flat tree of expressions with elements at odd indices being the
464+
// parents of the elements with even indices, so we only extract the "parent" elements here. In
465+
// case there is a single child, we extract it as a parent. See
466+
// https://github.com/github/codeql/pull/14119 and commit message for more details.
467+
if (expr.getNumElements() == 1) {
468+
entry.elements = dispatcher.fetchRepeatedLabels(expr.getElements());
469+
} else {
470+
for (int i = 1; i < expr.getNumElements(); i += 2) {
471+
entry.elements.emplace_back(dispatcher.fetchLabel(expr.getElement(i)));
472+
}
473+
}
464474
return entry;
465475
}
466476

0 commit comments

Comments
 (0)