mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 21:44:34 +00:00
fix: closure bug
This commit is contained in:
parent
439ba1d28e
commit
962e010c29
3 changed files with 23 additions and 0 deletions
|
@ -1382,6 +1382,16 @@ impl Context {
|
||||||
None
|
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) {
|
pub(crate) fn check_types(&self) {
|
||||||
if DEBUG_MODE {
|
if DEBUG_MODE {
|
||||||
for (_, ctx) in self.poly_types.iter() {
|
for (_, ctx) in self.poly_types.iter() {
|
||||||
|
|
|
@ -932,6 +932,11 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
|
||||||
if !ident.vi.is_toplevel()
|
if !ident.vi.is_toplevel()
|
||||||
&& ident.vi.def_namespace() != &self.module.context.name
|
&& ident.vi.def_namespace() != &self.module.context.name
|
||||||
&& ident.vi.kind.can_capture()
|
&& 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());
|
self.module.context.captured_names.push(ident.clone());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,3 +12,11 @@ func2! version: Int =
|
||||||
|
|
||||||
arr = func2!(1)
|
arr = func2!(1)
|
||||||
assert arr[0] == 1
|
assert arr[0] == 1
|
||||||
|
|
||||||
|
for! [1], _ =>
|
||||||
|
result = !""
|
||||||
|
push! left, right =
|
||||||
|
result.push! "| \{left} | \{right} |\n"
|
||||||
|
|
||||||
|
push! "a", "b"
|
||||||
|
assert result == "| a | b |\n"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue