From 8f95b79257cf1bbc99da3eb527d392e5671dc9e2 Mon Sep 17 00:00:00 2001 From: z78078 Date: Mon, 11 Jul 2022 15:55:55 +0800 Subject: [PATCH] nac3artiq: throw error message when constructor use rpc decorator (#306) Co-authored-by: z78078 Co-committed-by: z78078 --- nac3artiq/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index 1a58bb7e..4417a682 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -390,10 +390,17 @@ impl Nac3 { } } StmtKind::ClassDef { name, body, .. } => { - let class_obj = module.getattr(py, name.to_string()).unwrap(); + let class_name = name.to_string(); + let class_obj = module.getattr(py, &class_name).unwrap(); for stmt in body.iter() { if let StmtKind::FunctionDef { name, decorator_list, .. } = &stmt.node { if decorator_list.iter().any(|decorator| matches!(decorator.node, ExprKind::Name { id, .. } if id == "rpc".into())) { + if name == &"__init__".into() { + return Err(CompileError::new_err(format!( + "compilation failed\n----------\nThe constructor of class {} should not be decorated with rpc decorator (at {})", + class_name, stmt.location + ))); + } rpc_ids.push((Some((class_obj.clone(), *name)), def_id)); } }