From 13b36ccb0f7c2848a4899cec20e6fd03385e3158 Mon Sep 17 00:00:00 2001 From: Brummel Date: Sun, 10 May 2026 01:10:31 +0200 Subject: [PATCH] fix: mono pass seeds env.globals for recursive top-level fn in class workspace --- crates/ailang-check/src/mono.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/ailang-check/src/mono.rs b/crates/ailang-check/src/mono.rs index d6b76bf..f212c72 100644 --- a/crates/ailang-check/src/mono.rs +++ b/crates/ailang-check/src/mono.rs @@ -463,6 +463,20 @@ pub fn collect_mono_targets( env.rigid_vars.insert(v.clone()); } env.current_module = module_name.to_string(); + // Iter 22c (sibling of commit 5c5180f): seed `env.globals` from + // the current module's fns so `synth`'s `Term::Var` lookup + // (lib.rs:1678) resolves bare same-module references — most + // importantly self-recursive top-level fns. Mirrors + // `check_in_workspace` (lib.rs:1135-1139). Top-level fn names + // are only per-module-unique (workspace-wide collisions are + // legal), so seeding must be scoped to the current module — + // unlike the workspace-wide flat `env.types` / `env.ctor_index` + // tables that 5c5180f populated in `build_workspace_env`. + if let Some(g) = env.module_globals.get(module_name).cloned() { + for (n, t) in g { + env.globals.insert(n, t); + } + } let mut locals: IndexMap = IndexMap::new(); for (n, t) in f.params.iter().zip(param_tys.iter()) { @@ -805,6 +819,14 @@ pub(crate) fn collect_residuals_ordered( env.rigid_vars.insert(v.clone()); } env.current_module = module_name.to_string(); + // Iter 22c: same `env.globals` seeding as `collect_mono_targets` + // — see the comment there for rationale. Both fns re-run `synth` + // and must agree with the main check path's per-module env shape. + if let Some(g) = env.module_globals.get(module_name).cloned() { + for (n, t) in g { + env.globals.insert(n, t); + } + } let mut locals: IndexMap = IndexMap::new(); for (n, t) in f.params.iter().zip(param_tys.iter()) {