iter 22b.2.9: fix — superclass-walk tests, simplify class_superclasses map shape

This commit is contained in:
2026-05-09 18:59:15 +02:00
parent 7cff741632
commit b741a8ba05
4 changed files with 165 additions and 16 deletions
+16 -16
View File
@@ -1139,14 +1139,13 @@ fn check_in_workspace(
}
}
env.class_methods = class_methods;
let mut class_superclasses: BTreeMap<String, Option<String>> = BTreeMap::new();
let mut class_superclasses: BTreeMap<String, String> = BTreeMap::new();
for module in ws.modules.values() {
for def in &module.defs {
if let Def::Class(cd) = def {
class_superclasses.insert(
cd.name.clone(),
cd.superclass.as_ref().map(|s| s.class.clone()),
);
if let Some(sc) = &cd.superclass {
class_superclasses.insert(cd.name.clone(), sc.class.clone());
}
}
}
}
@@ -1321,10 +1320,9 @@ fn check_fn(f: &FnDef, env: &Env) -> Result<()> {
let mut effects = BTreeSet::new();
let mut subst = Subst::default();
let mut counter: u32 = 0;
// Iter 22b.2 (Task 9): per-fn residual class constraints. Every
// call to a class method inside the body pushes a
// [`ResidualConstraint`] here; after the body finishes, we
// compare against the expanded declared set.
// Per-fn residual class constraints. Every call to a class method
// inside the body pushes a [`ResidualConstraint`] here; after the
// body finishes, we compare against the expanded declared set.
let mut residuals: Vec<ResidualConstraint> = Vec::new();
let body_ty = synth(&f.body, &env, &mut locals, &mut effects, &f.name, &mut subst, &mut counter, &mut residuals)?;
unify(&ret_ty, &body_ty, &mut subst)?;
@@ -1407,11 +1405,11 @@ pub(crate) struct ResidualConstraint {
/// residual is satisfied.
fn expand_declared_constraints(
declared: &[Constraint],
class_superclasses: &BTreeMap<String, Option<String>>,
class_superclasses: &BTreeMap<String, String>,
) -> Vec<Constraint> {
let mut out: Vec<Constraint> = declared.to_vec();
for c in declared {
if let Some(Some(sc)) = class_superclasses.get(&c.class) {
if let Some(sc) = class_superclasses.get(&c.class) {
out.push(Constraint {
class: sc.clone(),
type_: c.type_.clone(),
@@ -2413,11 +2411,13 @@ pub struct Env {
/// safe (no overwrites). Read in [`synth`]'s `Term::Var` arm.
pub class_methods: BTreeMap<String, ClassMethodEntry>,
/// Iter 22b.2 (Task 9): one-step superclass expansion table.
/// Maps each class name to its (optional) superclass class name.
/// Used by [`check_fn`] to expand `Forall.constraints` for the
/// missing-constraint check (Decision 11: max one step). The
/// schema permits at most one superclass per class.
pub class_superclasses: BTreeMap<String, Option<String>>,
/// Maps each class name to its superclass class name. Absence from
/// the map means the class has no superclass — populated only for
/// classes that declare one. Used by [`check_fn`] to expand
/// `Forall.constraints` for the missing-constraint check
/// (Decision 11: max one step). The schema permits at most one
/// superclass per class.
pub class_superclasses: BTreeMap<String, String>,
}
/// Back-pointer from a ctor name to the ADT that declared it. Stored