diff --git a/crates/ailang-codegen/src/lib.rs b/crates/ailang-codegen/src/lib.rs index 3625bda..307d148 100644 --- a/crates/ailang-codegen/src/lib.rs +++ b/crates/ailang-codegen/src/lib.rs @@ -1679,20 +1679,22 @@ impl<'a> Emitter<'a> { } Ok(cref) } else { - // Local-first: current module's ctor table wins on conflict. + // Local-first: current module's ctor table wins on a + // type-matching hit. A local ctor with the same name but + // a DIFFERENT `type_name` is not a conflict — typecheck + // has already pinned which type is meant, so the lookup + // falls through to the imports-fallback. Only an + // exhausted scan yields `Err`. if let Some(cref) = self .module_ctor_index .get(self.module_name) .and_then(|m| m.get(ctor_name)) .cloned() { - if cref.type_name != type_name { - return Err(CodegenError::Internal(format!( - "ctor `{ctor_name}` belongs to `{}`, not `{type_name}`", - cref.type_name - ))); + if cref.type_name == type_name { + return Ok(cref); } - return Ok(cref); + // type_name mismatch — keep looking in imports. } // Iter 23.1: fallback — scan other modules for a bare ctor // whose declared `type_name` matches. The typechecker has @@ -1711,7 +1713,7 @@ impl<'a> Emitter<'a> { } } Err(CodegenError::Internal(format!( - "unknown ctor `{ctor_name}` in module `{}`", + "unknown ctor `{ctor_name}` for type `{type_name}` in module `{}`", self.module_name ))) }