Require parentheses around tuple in list comprehension filtering. This affects only the tuple that appears after 'if' inside a list comprehension. Since a truth value is expected, it's very unlikely to break existing code. It's technically a breaking change, but it's not worth introducing a flag for this. RELNOTES: Parentheses around the tuple are now mandatory in [a for b in c if 1, 2] PiperOrigin-RevId: 159218397
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java index 763b233..ed23432 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
@@ -817,7 +817,9 @@ comprehensionBuilder.addFor(loopVar, listExpression); } else if (token.kind == TokenKind.IF) { nextToken(); - comprehensionBuilder.addIf(parseExpression()); + // [x for x in li if 1, 2] # parse error + // [x for x in li if (1, 2)] # ok + comprehensionBuilder.addIf(parseNonTupleExpression(0)); } else if (token.kind == closingBracket) { nextToken(); return comprehensionBuilder.build();