fix: function hoisting errors --

One involving zero args being hoisted instead of compiled and replaced.
Second involving not updating a function's dependeny function scope. Which then hoisted to a lower scope and caused free unique
This commit is contained in:
Kasey White 2023-03-27 14:39:21 -04:00 committed by Lucas
parent 703429af98
commit 822bb4242a
2 changed files with 12 additions and 5 deletions

View File

@ -2522,7 +2522,7 @@ impl<'a> CodeGenerator<'a> {
if dependency_map.contains_key(&function.0) {
dependency_map.shift_remove(&function.0);
}
dependency_map.insert(function.0, function.1);
func_keys.extend(
funct_comp
.dependencies
@ -2535,6 +2535,15 @@ impl<'a> CodeGenerator<'a> {
})
.collect_vec(),
);
let func_scope = func_index_map.get(&function.0).unwrap().clone();
for dep in funct_comp.dependencies.iter() {
let Some(dep_scope) = func_index_map.get_mut(dep) else { unreachable!("Missing dependency scope.")};
*dep_scope = dep_scope.common_ancestor(&func_scope);
}
dependency_map.insert(function.0, function.1);
}
dependency_vec.extend(
@ -2816,9 +2825,7 @@ impl<'a> CodeGenerator<'a> {
for (index, ir) in ir_stack.to_vec().iter().enumerate().rev() {
match ir {
Air::Var {
scope,
constructor,
..
scope, constructor, ..
} => {
if let ValueConstructorVariant::ModuleFn {
name,

View File

@ -1473,7 +1473,7 @@ pub fn handle_func_dependencies(
let dep_scope = func_index_map.get(&dependency).unwrap();
if dep_scope.common_ancestor(func_scope) == *func_scope
if (dep_scope.common_ancestor(func_scope) == *func_scope && !depend_comp.args.is_empty())
|| function_component.args.is_empty()
{
let mut recursion_ir = vec![];