Skip to content

Commit 5d67c60

Browse files
Chilleefacebook-github-bot
authored andcommitted
Added error for classes that don't have an init function (#21880)
Summary: Fixes #21761 Pull Request resolved: #21880 Differential Revision: D15879205 Pulled By: Chillee fbshipit-source-id: 8b614970196b381357b6032a73eeaab0b7a4f667
1 parent 4fee532 commit 5d67c60

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
@@ -271,6 +271,10 @@ std::shared_ptr<SugaredValue> ClassValue::call(
271271
// Generate a new object of the right type, then call `__init__` on it
272272
auto& g = *m.graph();
273273
auto self = g.insertNode(g.createObject(type_))->output();
274+
if (!type_->getMethod("__init__")) {
275+
throw ErrorReport(loc)
276+
<< "Class " << type_->basename() << " does not have an __init__ function defined.";
277+
}
274278

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

0 commit comments

Comments
 (0)