[core] process variables before function instances
This commit is contained in:
parent
5076eccb6c
commit
16a3ac72e6
@ -434,7 +434,7 @@ impl TopLevelComposer {
|
||||
location: Location,
|
||||
) -> Result<(StrRef, DefinitionId, Option<Type>), String> {
|
||||
if self.keyword_list.contains(&name) {
|
||||
return Err(format!("cannot use keyword `{name}` as a class name (at {location})"));
|
||||
return Err(format!("cannot use keyword `{name}` as a variable name (at {location})"));
|
||||
}
|
||||
|
||||
let global_var_name =
|
||||
@ -469,10 +469,10 @@ impl TopLevelComposer {
|
||||
self.analyze_top_level_class_definition()?;
|
||||
self.analyze_top_level_class_fields_methods()?;
|
||||
self.analyze_top_level_function()?;
|
||||
self.analyze_top_level_variables()?;
|
||||
if inference {
|
||||
self.analyze_function_instance()?;
|
||||
}
|
||||
self.analyze_top_level_variables()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1410,7 +1410,7 @@ impl TopLevelComposer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// step 4, analyze and call type inferencer to fill the `instance_to_stmt` of
|
||||
/// step 5, analyze and call type inferencer to fill the `instance_to_stmt` of
|
||||
/// [`TopLevelDef::Function`]
|
||||
fn analyze_function_instance(&mut self) -> Result<(), HashSet<String>> {
|
||||
// first get the class constructor type correct for the following type check in function body
|
||||
@ -1941,7 +1941,7 @@ impl TopLevelComposer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Step 5. Analyze and populate the types of global variables.
|
||||
/// Step 4. Analyze and populate the types of global variables.
|
||||
fn analyze_top_level_variables(&mut self) -> Result<(), HashSet<String>> {
|
||||
let def_list = &self.definition_ast_list;
|
||||
let temp_def_list = self.extract_def_list();
|
||||
|
Loading…
Reference in New Issue
Block a user