Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ public List<ElemT> convert(Object x, Object what, LabelConverter labelConverter)
throws ConversionException {
Iterable<?> iterable;

if (x instanceof Map) {
throw new ConversionException(this, x, what);
}

if (x instanceof Iterable) {
iterable = (Iterable<?>) x;
} else if (x instanceof Depset) {
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/google/devtools/build/lib/packages/TypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ public void testNonStringList() throws Exception {
.isEqualTo("expected value of type 'list(string)' for blah, but got 3 (int)");
}

@Test
public void testStringListRejectsDict() throws Exception {
Type.ConversionException e =
assertThrows(
Type.ConversionException.class,
() -> Types.STRING_LIST.convert(ImmutableMap.of("foo", "bar"), "myattr"));
assertThat(e)
.hasMessageThat()
.isEqualTo(
"expected value of type 'list(string)' for myattr,"
+ " but got {\"foo\": \"bar\"} (Map)");
}

@Test
public void testStringListBadElements() throws Exception {
Object input = Arrays.<Object>asList("foo", "bar", StarlarkInt.of(1));
Expand Down
Loading