From a720b0699e26de56c56cd691275a93ec23723e29 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 7 Oct 2026 13:58:15 +0100 Subject: [PATCH] Release nested procedures before running the escape analysis on their parent --- src/check_decl.cpp | 12 ------------ src/checker.cpp | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/check_decl.cpp b/src/check_decl.cpp index f3ad5a7a1..438992f53 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -2531,18 +2531,6 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de } check_close_scope(ctx); - // the entry point of an executable only returns as the program ends - bool is_entry_point = false; - if (build_context.build_mode == BuildMode_Executable && - !build_context.no_entry_point && - build_context.command_kind != Command_test) { - Entity *proc_entity = decl->entity.load(); - is_entry_point = proc_entity != nullptr && proc_entity == ctx->info->entry_point; - } - if (!is_entry_point) { - check_proc_escapes(type, body); - } - check_scope_usage(ctx->checker, ctx->scope, check_vet_flags(body)); add_deps_from_child_to_parent(decl); diff --git a/src/checker.cpp b/src/checker.cpp index b3a508e69..251af1a6c 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -6844,7 +6844,6 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u ErrorInstantiations prev_instantiations = global_error_context.instantiations; global_error_context.instantiations = {pi->generated_from_polymorphic ? pi : pi->poly_parent, nullptr}; bool body_was_checked = check_proc_body(&ctx, pi->token, pi->decl, pi->type, pi->body); - global_error_context.instantiations = prev_instantiations; if (body_was_checked) { pi->decl->proc_checked_state.store(ProcCheckedState_Checked); @@ -6875,6 +6874,21 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u } array_free(&nested); + if (body_was_checked) { + // the entry point of an executable only returns as the program ends + bool is_entry_point = false; + if (build_context.build_mode == BuildMode_Executable && + !build_context.no_entry_point && + build_context.command_kind != Command_test) { + Entity *e = pi->decl->entity; + is_entry_point = e != nullptr && e == c->info.entry_point; + } + if (!is_entry_point) { + check_proc_escapes(pi->type, pi->body); + } + } + global_error_context.instantiations = prev_instantiations; + add_untyped_expressions(&c->info, ctx.untyped); return true;