nac3artiq: throw error message when constructor use rpc decorator #306
|
@ -393,21 +393,21 @@ impl Nac3 {
|
||||||
let class_obj = module.getattr(py, name.to_string()).unwrap();
|
let class_obj = module.getattr(py, name.to_string()).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 {
|
||||||
// checking: constructor __init__ must not be decorated with rpc
|
if let Some(location) = decorator_list
|
||||||
if name == &"__init__".into() {
|
.iter()
|
||||||
for decorator in decorator_list.iter() {
|
.find_map(|ast::Located { location, node, .. } | {
|
||||||
if let ast::Located { location, node: ExprKind::Name { id, .. }, .. } = decorator {
|
match node {
|
||||||
if id == &"rpc".into() {
|
ExprKind::Name { id, .. } if id == &"rpc".into() => Some(location),
|
||||||
return Err(CompileError::new_err(format!(
|
_ => None,
|
||||||
"compilation failed\n----------\nConstructor __init__ function should not decorated with rpc decorator (at {})",
|
|
||||||
location
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
{
|
||||||
|
if name == &"__init__".into() {
|
||||||
|
return Err(CompileError::new_err(format!(
|
||||||
|
"compilation failed\n----------\nConstructor __init__ function should not decorated with rpc decorator (at {})",
|
||||||
|
location
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if decorator_list.iter().any(|decorator| matches!(decorator.node, ExprKind::Name { id, .. } if id == "rpc".into())) {
|
|
||||||
rpc_ids.push((Some((class_obj.clone(), *name)), def_id));
|
rpc_ids.push((Some((class_obj.clone(), *name)), def_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue