Skip to content

Commit f3d6ebe

Browse files
committed
Added error for classes that don't have an init function
1 parent b858f42 commit f3d6ebe

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

torch/csrc/jit/script/sugared_value.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ std::shared_ptr<SugaredValue> ClassValue::call(
248248
// Generate a new object of the right type, then call `__init__` on it
249249
auto& g = *m.graph();
250250
auto self = g.insertNode(g.createObject(type_))->output();
251+
if (!type_->hasAttribute("__init__")) {
252+
throw ErrorReport(loc)
253+
<< "Class " << type_->basename() << " does not have an __init__ function defined.";
254+
}
251255

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

0 commit comments

Comments
 (0)