Skip to content

Commit

Permalink
fix empty annotated list
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias Ellison committed Nov 5, 2020
1 parent 99a53db commit 213fcc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/jit/test_list_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def foo3():
return list(list("abc"))

self.checkScript(foo3, ())
FileCheck.check_count("aten::list", 2, exactly=True)
FileCheck().check_count("aten::list", 2, exactly=True).run(torch.jit.script(foo3).graph)

def test_min_bool_list(self):
def jit_min_list(a, b):
Expand Down
7 changes: 6 additions & 1 deletion torch/csrc/jit/frontend/ir_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,12 @@ struct to_ir {
case prim::list: {
if (apply.inputs().size() == 0) {
TypePtr type = type_hint ? type_hint : ListType::ofTensors();
return std::make_shared<SimpleValue>(graph->insertNode(graph->createList(type, {}))->output());
if (!type->cast<ListType>()) {
throw ErrorReport(apply.range())
<< "Expected list type annotation for list(), found "
<< type_hint->repr_str();
}
return std::make_shared<SimpleValue>(graph->insertNode(graph->createList(type->expect<ListType>()->getElementType(), {}))->output());
}
// list(iter) desugars to [_elem for _elem in iter]
checkApplyNumInputs(apply, 1);
Expand Down

0 comments on commit 213fcc5

Please sign in to comment.