iter 22b.2.8: fix — fold double-match, IndexMap parity, broader contract test

This commit is contained in:
2026-05-09 18:37:49 +02:00
parent 17605a3327
commit afa06a3f3d
2 changed files with 112 additions and 7 deletions
+27 -7
View File
@@ -857,7 +857,11 @@ pub struct ModuleGlobals {
/// Class-method names, by method name. Populated in
/// [`build_module_globals`] from `Def::Class` entries; consulted by
/// the 22b.2 `missing-constraint` / `no-instance` arms (Tasks 9 / 10).
pub class_methods: BTreeMap<String, ClassMethodEntry>,
/// `IndexMap` matches the sibling [`Self::fns`] channel and preserves
/// definition order — Tasks 9 / 10 may surface diagnostics in source
/// order, and downstream consumers should not depend on a sorted
/// iteration order they did not ask for.
pub class_methods: IndexMap<String, ClassMethodEntry>,
}
impl ModuleGlobals {
@@ -873,6 +877,15 @@ impl ModuleGlobals {
.get(name)
.map(|e| e.class_name.as_str())
}
/// The full [`ClassMethodEntry`] for method `name`, or `None` if
/// `name` is not a class method in this module. Tasks 9 / 10 use
/// this to read `method_ty` and `defining_module` together; the
/// narrower `has_class_method` / `class_method_class` accessors
/// stay for callers that only need a yes/no or the class name.
pub fn class_method(&self, name: &str) -> Option<&ClassMethodEntry> {
self.class_methods.get(name)
}
}
/// Iter 22b.2: per-class-method metadata stored in
@@ -935,24 +948,31 @@ pub fn build_module_globals(
// missing-method / method-name-collision) is enforced
// earlier at `workspace::build_registry`.
match def {
Def::Fn(_) | Def::Const(_) | Def::Type(_) => {
Def::Fn(f) => {
if globals.fns.contains_key(def_name) {
return Err(CheckError::Def(
def_name.to_string(),
Box::new(CheckError::DuplicateDef(def_name.to_string())),
));
}
}
Def::Class(_) | Def::Instance(_) => {}
}
match def {
Def::Fn(f) => {
globals.fns.insert(def_name.to_string(), f.ty.clone());
}
Def::Const(c) => {
if globals.fns.contains_key(def_name) {
return Err(CheckError::Def(
def_name.to_string(),
Box::new(CheckError::DuplicateDef(def_name.to_string())),
));
}
globals.fns.insert(def_name.to_string(), c.ty.clone());
}
Def::Type(_) => {
if globals.fns.contains_key(def_name) {
return Err(CheckError::Def(
def_name.to_string(),
Box::new(CheckError::DuplicateDef(def_name.to_string())),
));
}
globals.fns.insert(
def_name.to_string(),
Type::Con {