Skip to content

Commit bd0a882

Browse files
asgerfCopilot
andcommitted
JS: Fix CFG successor edges for parenthesized optional chain bases
When a parenthesized expression is the callee/object of an optional chain step (e.g. `(null)?.()`), the postVisitChainable method was writing CFG successor edges FROM the ParenthesizedExpression node. Since ParenthesizedExpression nodes are now bypassed and have no DB entry, this caused VALUE_NOT_IN_TYPE errors in the successor relation. Fix by unwrapping ParenthesizedExpression before writing the successor edge, so the edge is written from the inner expression instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c89e541 commit bd0a882

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

javascript/extractor/src/com/semmle/js/extractor/CFGExtractor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,10 @@ private void preVisitChainable(Chainable chainable, Expression base, SuccessorIn
17781778

17791779
private void postVisitChainable(Chainable chainable, Expression base, boolean optional) {
17801780
if (optional) {
1781+
// Unwrap parenthesized expressions since they have no DB entry.
1782+
while (base instanceof ParenthesizedExpression) {
1783+
base = ((ParenthesizedExpression) base).getExpression();
1784+
}
17811785
writeSuccessors(base, chainRootSuccessors.get(chainable).getSuccessors(false));
17821786
}
17831787
chainRootSuccessors.remove(chainable);

0 commit comments

Comments
 (0)