From 5c5180fc489793a7de8da57af511191a4683b37f Mon Sep 17 00:00:00 2001 From: Brummel Date: Sat, 9 May 2026 22:43:54 +0200 Subject: [PATCH] fix: mono pass seeds env.types and env.ctor_index for user ADTs --- crates/ailang-check/src/mono.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/ailang-check/src/mono.rs b/crates/ailang-check/src/mono.rs index e5a2560..d6b76bf 100644 --- a/crates/ailang-check/src/mono.rs +++ b/crates/ailang-check/src/mono.rs @@ -403,6 +403,30 @@ pub fn build_workspace_env(ws: &Workspace) -> crate::Env { } } } + + // Iter 22c: seed `env.types` and `env.ctor_index` from every + // module's `Def::Type` entries. `synth`'s bare-name `Term::Ctor` + // path (and three sibling sites in `lib.rs`) consult these flat + // tables; without them, re-running `synth` on an instance method + // body whose type references a user ADT yields `UnknownType`. + // Workspace-wide flat tables are safe here because `check_workspace` + // has already accepted the workspace, so duplicate names cannot + // occur. Mirrors `check_in_workspace` (lib.rs:1099-1128). + for m in ws.modules.values() { + for d in &m.defs { + if let Def::Type(td) = d { + for c in &td.ctors { + env.ctor_index.insert( + c.name.clone(), + crate::CtorRef { + type_name: td.name.clone(), + }, + ); + } + env.types.insert(td.name.clone(), td.clone()); + } + } + } env }