@@ -439,6 +439,12 @@ void SourceImporterImpl::importClass(
439
439
switch (statement.kind ()) {
440
440
case TK_ASSIGN: {
441
441
const auto assign = Assign (statement);
442
+ auto check_assign_values = [&assign](const std::string& name) {
443
+ TORCH_CHECK (
444
+ assign.rhs ().present (),
445
+ " Malformed assignment statement: missing values to assign in " ,
446
+ name);
447
+ };
442
448
switch (assign.lhs ().kind ()) {
443
449
case TK_VAR: {
444
450
const auto name = Var (assign.lhs ()).name ().name ();
@@ -451,6 +457,7 @@ void SourceImporterImpl::importClass(
451
457
is_module,
452
458
" Assignments in class body only "
453
459
" supported on modules right now" );
460
+ check_assign_values (name);
454
461
const auto param_list = ListLiteral (assign.rhs ().get ()).inputs ();
455
462
for (const auto & param : param_list) {
456
463
parameter_names.insert (StringLiteral (param).text ());
@@ -461,6 +468,7 @@ void SourceImporterImpl::importClass(
461
468
} else if (name == " __buffers__" ) {
462
469
TORCH_INTERNAL_ASSERT (
463
470
is_module, " Buffers only exist on modules at the moment" );
471
+ check_assign_values (name);
464
472
const auto buffer_list = ListLiteral (assign.rhs ().get ()).inputs ();
465
473
for (const auto & buffer : buffer_list) {
466
474
buffer_names.insert (StringLiteral (buffer).text ());
@@ -469,6 +477,7 @@ void SourceImporterImpl::importClass(
469
477
TORCH_INTERNAL_ASSERT (
470
478
is_module,
471
479
" Forward pre hooks only exist on modules at the moment" );
480
+ check_assign_values (name);
472
481
const auto pre_hook_list =
473
482
ListLiteral (assign.rhs ().get ()).inputs ();
474
483
for (const auto & pre_hook : pre_hook_list) {
@@ -480,6 +489,7 @@ void SourceImporterImpl::importClass(
480
489
TORCH_INTERNAL_ASSERT (
481
490
is_module,
482
491
" Forward hooks only exist on modules at the moment" );
492
+ check_assign_values (name);
483
493
const auto hook_list = ListLiteral (assign.rhs ().get ()).inputs ();
484
494
for (const auto & hook : hook_list) {
485
495
std::string hook_name = StringLiteral (hook).text ();
0 commit comments