Skip to content

Commit 4d1fe9b

Browse files
committed
Fix NodePrinter crash on Comprehension.Clause
1 parent edc799e commit 4d1fe9b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/main/java/net/starlark/java/syntax/NodePrinter.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ void printNode(Node n) {
4141
} else if (n instanceof Statement) {
4242
printStmt((Statement) n);
4343

44+
} else if (n instanceof Comprehension.Clause) {
45+
printClause((Comprehension.Clause) n);
46+
4447
} else if (n instanceof StarlarkFile) {
4548
StarlarkFile file = (StarlarkFile) n;
4649
// Only statements are printed, not comments.
@@ -277,17 +280,7 @@ private void printExpr(Expression expr) {
277280
printNode(comp.getBody()); // Expression or DictExpression.Entry
278281
for (Comprehension.Clause clause : comp.getClauses()) {
279282
buf.append(' ');
280-
if (clause instanceof Comprehension.For) {
281-
Comprehension.For forClause = (Comprehension.For) clause;
282-
buf.append("for ");
283-
printExpr(forClause.getVars());
284-
buf.append(" in ");
285-
printExpr(forClause.getIterable());
286-
} else {
287-
Comprehension.If ifClause = (Comprehension.If) clause;
288-
buf.append("if ");
289-
printExpr(ifClause.getCondition());
290-
}
283+
printClause(clause);
291284
}
292285
buf.append(comp.isDict() ? '}' : ']');
293286
break;
@@ -482,4 +475,18 @@ private void printExpr(Expression expr) {
482475
}
483476
}
484477
}
478+
479+
private void printClause(Comprehension.Clause clause) {
480+
if (clause instanceof Comprehension.For) {
481+
Comprehension.For forClause = (Comprehension.For) clause;
482+
buf.append("for ");
483+
printExpr(forClause.getVars());
484+
buf.append(" in ");
485+
printExpr(forClause.getIterable());
486+
} else {
487+
Comprehension.If ifClause = (Comprehension.If) clause;
488+
buf.append("if ");
489+
printExpr(ifClause.getCondition());
490+
}
491+
}
485492
}

0 commit comments

Comments
 (0)