aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-06-23 16:03:00 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-26 18:31:16 +0200
commitc32efc8375cf482e795a43ecf4f009971722e71a (patch)
tree6d52f53c789b0d5437d78ebf922bbcf271ef695e /src/main/java/com/google/devtools
parent1d8cd59173e9c1e2fd7fd03dd4b2a0ae8a35ef4b (diff)
Make len(depset()) fail when --incompatible_depset_is_not_iterable is set
RELNOTES: None. PiperOrigin-RevId: 159945244
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java12
2 files changed, 12 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
index 1e3b13486e..6cc14f295e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
@@ -337,8 +337,8 @@ public final class EvalUtils {
if (env != null && env.getSemantics().incompatibleDepsetIsNotIterable) {
throw new EvalException(
loc,
- "type 'depset' is not iterable. Use the `to_list()` method to get a list. "
- + "Use --incompatible_depset_is_not_iterable to temporarily disable this check.");
+ "type 'depset' is not iterable. Use the `to_list()` method to get a list. Use "
+ + "--incompatible_depset_is_not_iterable=false to temporarily disable this check.");
}
return set.toCollection();
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
index afa4afd388..2f25c3b1f9 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
@@ -1607,11 +1607,19 @@ public class MethodLibrary {
returnType = Integer.class,
doc = "Returns the length of a string, list, tuple, depset, or dictionary.",
parameters = {@Param(name = "x", doc = "The object to check length of.")},
- useLocation = true
+ useLocation = true,
+ useEnvironment = true
)
private static final BuiltinFunction len =
new BuiltinFunction("len") {
- public Integer invoke(Object x, Location loc) throws EvalException {
+ public Integer invoke(Object x, Location loc, Environment env) throws EvalException {
+ if (env.getSemantics().incompatibleDepsetIsNotIterable && x instanceof SkylarkNestedSet) {
+ throw new EvalException(
+ loc,
+ EvalUtils.getDataTypeName(x)
+ + " is not iterable. Use --incompatible_depset_is_not_iterable=false to "
+ + "temporarily disable this check.");
+ }
int l = EvalUtils.size(x);
if (l == -1) {
throw new EvalException(loc, EvalUtils.getDataTypeName(x) + " is not iterable");