aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-06-23 16:55:01 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-26 18:32:12 +0200
commit0f5b7205c09112a1d1ce74bad666054e5c902463 (patch)
tree3338384fd9b3e9dfb1c97fbec1998287d6a94cce /src/main/java
parente94ffea3bd5ee8669c077d0007c617bd40323244 (diff)
Forbid 'in' operator on depset with --incompatible_depset_is_not_iterable
RELNOTES: None. PiperOrigin-RevId: 159948522
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
index 0e03157a2d..2274076d88 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
@@ -69,8 +69,18 @@ public final class BinaryOperatorExpression extends Expression {
}
/** Implements the "in" operator. */
- private static boolean in(Object lval, Object rval, Location location) throws EvalException {
- if (rval instanceof SkylarkQueryable) {
+ private static boolean in(Object lval, Object rval, Location location, Environment env)
+ throws EvalException {
+ if (env.getSemantics().incompatibleDepsetIsNotIterable && rval instanceof SkylarkNestedSet) {
+ throw new EvalException(
+ location,
+ "argument of type '"
+ + EvalUtils.getDataTypeName(rval)
+ + "' is not iterable. "
+ + "in operator only works on lists, tuples, dicts and strings. "
+ + "Use --incompatible_depset_is_not_iterable=false to temporarily disable "
+ + "this check.");
+ } else if (rval instanceof SkylarkQueryable) {
return ((SkylarkQueryable) rval).containsKey(lval, location);
} else if (rval instanceof String) {
if (lval instanceof String) {
@@ -159,10 +169,10 @@ public final class BinaryOperatorExpression extends Expression {
return compare(lval, rval, location) >= 0;
case IN:
- return in(lval, rval, location);
+ return in(lval, rval, location, env);
case NOT_IN:
- return !in(lval, rval, location);
+ return !in(lval, rval, location, env);
default:
throw new AssertionError("Unsupported binary operator: " + operator);