|
|
@ -228,6 +228,7 @@ impl TopLevelComposer {
|
|
|
|
// subclass of other exception classes.
|
|
|
|
// subclass of other exception classes.
|
|
|
|
let mut contains_constructor = bases
|
|
|
|
let mut contains_constructor = bases
|
|
|
|
.iter().any(|base| matches!(base.node, ast::ExprKind::Name { id, .. } if id == exception_id));
|
|
|
|
.iter().any(|base| matches!(base.node, ast::ExprKind::Name { id, .. } if id == exception_id));
|
|
|
|
|
|
|
|
|
|
|
|
for b in body {
|
|
|
|
for b in body {
|
|
|
|
if let ast::StmtKind::FunctionDef { name: method_name, .. } = &b.node {
|
|
|
|
if let ast::StmtKind::FunctionDef { name: method_name, .. } = &b.node {
|
|
|
|
if method_name == &init_id {
|
|
|
|
if method_name == &init_id {
|
|
|
@ -298,7 +299,9 @@ impl TopLevelComposer {
|
|
|
|
self.definition_ast_list.push((def, Some(ast)));
|
|
|
|
self.definition_ast_list.push((def, Some(ast)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let result_ty = if contains_constructor { Some(constructor_ty) } else { None };
|
|
|
|
// Quick way to fix #221, contains constructor can be used in the future for some implementation if required.
|
|
|
|
|
|
|
|
let result_ty = if contains_constructor { Some(constructor_ty) } else { Some(constructor_ty) };
|
|
|
|
|
|
|
|
|
|
|
|
Ok((class_name, DefinitionId(class_def_id), result_ty))
|
|
|
|
Ok((class_name, DefinitionId(class_def_id), result_ty))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1470,7 +1473,7 @@ impl TopLevelComposer {
|
|
|
|
|
|
|
|
|
|
|
|
/// step 5, analyze and call type inferecer to fill the `instance_to_stmt` of topleveldef::function
|
|
|
|
/// step 5, analyze and call type inferecer to fill the `instance_to_stmt` of topleveldef::function
|
|
|
|
fn analyze_function_instance(&mut self) -> Result<(), String> {
|
|
|
|
fn analyze_function_instance(&mut self) -> Result<(), String> {
|
|
|
|
// first get the class contructor type correct for the following type check in function body
|
|
|
|
// first get the class constructor type correct for the following type check in function body
|
|
|
|
// also do class field instantiation check
|
|
|
|
// also do class field instantiation check
|
|
|
|
let init_str_id = "__init__".into();
|
|
|
|
let init_str_id = "__init__".into();
|
|
|
|
let mut definition_extension = Vec::new();
|
|
|
|
let mut definition_extension = Vec::new();
|
|
|
@ -1581,7 +1584,7 @@ impl TopLevelComposer {
|
|
|
|
return Ok(());
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut init_id: Option<DefinitionId> = None;
|
|
|
|
let mut init_id: Option<DefinitionId> = None;
|
|
|
|
// get the class contructor type correct
|
|
|
|
// get the class constructor type correct
|
|
|
|
let (contor_args, contor_type_vars) = {
|
|
|
|
let (contor_args, contor_type_vars) = {
|
|
|
|
let mut constructor_args: Vec<FuncArg> = Vec::new();
|
|
|
|
let mut constructor_args: Vec<FuncArg> = Vec::new();
|
|
|
|
let mut type_vars: HashMap<u32, Type> = HashMap::new();
|
|
|
|
let mut type_vars: HashMap<u32, Type> = HashMap::new();
|
|
|
|