update function analyze_single_class_methods_fields in file nac3core/src/toplevel/composer.rs to throw error "class <class-name> constructor __init__ (at <location>) must not be decorated with rpc" when the constructor __init__ is decorated with decorator rpc

This commit is contained in:
z78078 2022-07-07 15:50:56 +08:00
parent ebd25af38b
commit df9df84879
1 changed files with 16 additions and 1 deletions

View File

@ -1067,12 +1067,27 @@ impl TopLevelComposer {
let mut defined_fields: HashSet<_> = HashSet::new(); let mut defined_fields: HashSet<_> = HashSet::new();
for b in class_body_ast { for b in class_body_ast {
match &b.node { match &b.node {
ast::StmtKind::FunctionDef { args, returns, name, .. } => { ast::StmtKind::FunctionDef { args, returns, name, decorator_list, .. } => {
let (method_dummy_ty, method_id) = let (method_dummy_ty, method_id) =
Self::get_class_method_def_info(class_methods_def, *name)?; Self::get_class_method_def_info(class_methods_def, *name)?;
let mut method_var_map: HashMap<u32, Type> = HashMap::new(); let mut method_var_map: HashMap<u32, Type> = HashMap::new();
// This part check if __init__ method decorate with inappropriate decorator (rpc)
if name == &"__init__".into() {
if let Some(_) = decorator_list
.iter()
.find(|ast::Located { node, .. }| match node {
&ast::ExprKind::Name { id, .. } => id == "rpc".into(),
_ => false
}) {
return Err(format!(
"class {} constructor {} (at {}) must not be decorated with rpc",
_class_name, name, b.location
));
}
}
let arg_types: Vec<FuncArg> = { let arg_types: Vec<FuncArg> = {
// check method parameters cannot have same name // check method parameters cannot have same name
let mut defined_parameter_name: HashSet<_> = HashSet::new(); let mut defined_parameter_name: HashSet<_> = HashSet::new();