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();
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index bd4f18c..dc2d021 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -370,7 +370,7 @@
.testExactOrder("['foo/%s.java' % x for x in []]")
.testExactOrder("['foo/%s.java' % y for y in ['bar', 'wiz', 'quux']]", "foo/bar.java",
"foo/wiz.java", "foo/quux.java")
- .testExactOrder("['%s/%s.java' % (z, t) " + "for z in ['foo', 'bar'] "
+ .testExactOrder("['%s/%s.java' % (z, t) for z in ['foo', 'bar'] "
+ "for t in ['baz', 'wiz', 'quux']]",
"foo/baz.java",
"foo/wiz.java",
@@ -378,7 +378,7 @@
"bar/baz.java",
"bar/wiz.java",
"bar/quux.java")
- .testExactOrder("['%s/%s.java' % (b, b) " + "for a in ['foo', 'bar'] "
+ .testExactOrder("['%s/%s.java' % (b, b) for a in ['foo', 'bar'] "
+ "for b in ['baz', 'wiz', 'quux']]",
"baz/baz.java",
"wiz/wiz.java",
@@ -386,8 +386,8 @@
"baz/baz.java",
"wiz/wiz.java",
"quux/quux.java")
- .testExactOrder("['%s/%s.%s' % (c, d, e) " + "for c in ['foo', 'bar'] "
- + "for d in ['baz', 'wiz', 'quux'] " + "for e in ['java', 'cc']]",
+ .testExactOrder("['%s/%s.%s' % (c, d, e) for c in ['foo', 'bar'] "
+ + "for d in ['baz', 'wiz', 'quux'] for e in ['java', 'cc']]",
"foo/baz.java",
"foo/baz.cc",
"foo/wiz.java",
@@ -399,7 +399,9 @@
"bar/wiz.java",
"bar/wiz.cc",
"bar/quux.java",
- "bar/quux.cc");
+ "bar/quux.cc")
+ .testExactOrder("[i for i in (1, 2)]", 1, 2)
+ .testExactOrder("[i for i in [2, 3] or [1, 2]]", 2, 3);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index c28adaa..b5eedb2 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -689,6 +689,10 @@
parseExpression("[x for x for y in ['a']]");
assertContainsError("syntax error at 'for'");
clearEvents();
+
+ parseExpression("[x for x for y in 1, 2]");
+ assertContainsError("syntax error at 'for'");
+ clearEvents();
}
@Test
diff --git a/third_party/ijar/BUILD b/third_party/ijar/BUILD
index 45fca3a..7836ea1 100644
--- a/third_party/ijar/BUILD
+++ b/third_party/ijar/BUILD
@@ -90,9 +90,3 @@
srcs = glob(["**"]) + ["//third_party/ijar/test:srcs"],
visibility = ["//third_party:__pkg__"],
)
-
-filegroup(
- name = "embedded_tools",
- srcs = glob(["**"]),
- visibility = ["//visibility:public"],
-)