diff options
author | 2015-08-10 15:13:34 +0000 | |
---|---|---|
committer | 2015-08-11 07:51:30 +0000 | |
commit | e083a9167dff6804a2ff788bcf843e29fa1d821d (patch) | |
tree | 80b3993fffd4a869d2d9e483df7c0807f4bace27 /src/main/java/com/google/devtools/build/lib/syntax | |
parent | 310a1ebff45fb19d36edf0e09afda724de1158c8 (diff) |
Allow heterogeneous lists in Skylark.
This brings consistency between BUILD and Skylark interpreters. It also brings
consistency with dicts (e.g. **kwargs can contain anything and kwargs.values
is allowed).
--
MOS_MIGRATED_REVID=100278980
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java index cbcf21a95c..fb4f2457d4 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java @@ -362,23 +362,15 @@ public abstract class SkylarkList implements Iterable<Object> { if (elements.isEmpty()) { return EMPTY_LIST; } - return new SimpleSkylarkList( - ImmutableList.copyOf(elements), false, getContentType(elements, loc)); + return new SimpleSkylarkList(ImmutableList.copyOf(elements), false, getContentType(elements)); } - private static SkylarkType getContentType(Collection<?> elements, Location loc) + private static SkylarkType getContentType(Collection<?> elements) throws EvalException { SkylarkType type = SkylarkType.TOP; for (Object element : elements) { SkylarkType elementType = SkylarkType.typeOf(element); - SkylarkType inter = SkylarkType.intersection(type, elementType); - if (inter == SkylarkType.BOTTOM) { - throw new EvalException(loc, String.format( - "Incompatible types in list: found a %s but the previous elements were %ss", - elementType, type)); - } else { - type = inter; - } + type = SkylarkType.intersection(type, elementType); } return type; } @@ -399,10 +391,6 @@ public abstract class SkylarkList implements Iterable<Object> { return left; } SkylarkType type = SkylarkType.intersection(left.contentType, right.contentType); - if (type == SkylarkType.BOTTOM) { - throw new EvalException(loc, String.format("cannot concatenate list of %s with list of %s", - left.contentType, right.contentType)); - } return new ConcatenatedSkylarkList(left, right, left.isTuple(), type); } |