nac3artiq: throw error message when constructor use rpc decorator #306

Merged
sb10q merged 10 commits from issue-221 into master 2022-07-11 15:55:55 +08:00
1 changed files with 4 additions and 3 deletions
Showing only changes of commit 11af619455 - Show all commits

View File

@ -390,7 +390,8 @@ impl Nac3 {
} }
} }
StmtKind::ClassDef { name, body, .. } => { 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() { for stmt in body.iter() {
if let StmtKind::FunctionDef { name, decorator_list, .. } = &stmt.node { if let StmtKind::FunctionDef { name, decorator_list, .. } = &stmt.node {
if let Some(location) = decorator_list if let Some(location) = decorator_list
@ -405,8 +406,8 @@ impl Nac3 {
// This part check if __init__ method decorate with inappropriate decorator (rpc) // This part check if __init__ method decorate with inappropriate decorator (rpc)
if name == &"__init__".into() { if name == &"__init__".into() {
return Err(CompileError::new_err(format!( return Err(CompileError::new_err(format!(
"compilation failed\n----------\nConstructor __init__ function should not decorated with rpc decorator (at {})", "compilation failed\n----------\nClass {} Constructor __init__ function should not decorated with rpc decorator (at {})",
location class_name, location
))); )));
} }
rpc_ids.push((Some((class_obj.clone(), *name)), def_id)); rpc_ids.push((Some((class_obj.clone(), *name)), def_id));