Skip to content
Closed
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
4 changes: 4 additions & 0 deletions torch/csrc/jit/script/sugared_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ std::shared_ptr<SugaredValue> ClassValue::call(
// Generate a new object of the right type, then call `__init__` on it
auto& g = *m.graph();
auto self = g.insertNode(g.createObject(type_))->output();
if (!type_->getMethod("__init__")) {
throw ErrorReport(loc)
<< "Class " << type_->basename() << " does not have an __init__ function defined.";
}

// Call the init function
MethodValue(self, "__init__").call(loc, m, inputs, attributes, n_binders);
Expand Down