fix: closure bug

This commit is contained in:
Shunsuke Shibayama 2023-11-18 19:43:06 +09:00
parent 439ba1d28e
commit 962e010c29
3 changed files with 23 additions and 0 deletions

View file

@ -1382,6 +1382,16 @@ impl Context {
None
}
pub fn current_function_ctx(&self) -> Option<&Context> {
if self.kind.is_subr() {
Some(self)
} else if let Some(outer) = self.get_outer() {
outer.current_function_ctx()
} else {
None
}
}
pub(crate) fn check_types(&self) {
if DEBUG_MODE {
for (_, ctx) in self.poly_types.iter() {

View file

@ -932,6 +932,11 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
if !ident.vi.is_toplevel()
&& ident.vi.def_namespace() != &self.module.context.name
&& ident.vi.kind.can_capture()
&& self
.module
.context
.current_function_ctx()
.is_some_and(|ctx| ctx.control_kind().is_none())
{
self.module.context.captured_names.push(ident.clone());
}