From 4e6d8162bfa7149c3b947c6c759f82c1f52ef4d7 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 14 Jul 2024 13:22:42 -0400 Subject: Fix issue with bindings inside closures --- compile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index f56604d8..a49ab29c 100644 --- a/compile.c +++ b/compile.c @@ -81,8 +81,9 @@ static table_t *get_closed_vars(env_t *env, ast_t *lambda_ast) // Find which variables are captured in the closure: env_t *tmp_scope = fresh_scope(body_scope); for (ast_list_t *stmt = Match(lambda->body, Block)->statements; stmt; stmt = stmt->next) { + bind_statement(tmp_scope, stmt->ast); type_t *stmt_type = get_type(tmp_scope, stmt->ast); - if (stmt->next || (stmt_type->tag == VoidType || stmt_type->tag == AbortType || get_type(body_scope, stmt->ast)->tag == ReturnType)) + if (stmt->next || (stmt_type->tag == VoidType || stmt_type->tag == AbortType || get_type(tmp_scope, stmt->ast)->tag == ReturnType)) (void)compile_statement(tmp_scope, stmt->ast); else (void)compile(tmp_scope, stmt->ast); @@ -1776,6 +1777,7 @@ CORD compile(env_t *env, ast_t *ast) CORD body = CORD_EMPTY; for (ast_list_t *stmt = Match(lambda->body, Block)->statements; stmt; stmt = stmt->next) { + bind_statement(body_scope, stmt->ast); if (stmt->next || ret_t->tag == VoidType || ret_t->tag == AbortType || get_type(body_scope, stmt->ast)->tag == ReturnType) body = CORD_all(body, compile_statement(body_scope, stmt->ast), "\n"); else -- cgit v1.2.3