iter ct.1.6: wire validator into load_workspace; refresh kind-mismatch test

This commit is contained in:
2026-05-11 01:42:45 +02:00
parent d3280e9adf
commit 727d2c13ec
+23 -12
View File
@@ -452,6 +452,12 @@ pub fn load_workspace(entry_path: &Path) -> Result<Workspace, WorkspaceLoadError
let prelude = load_prelude();
modules.insert("prelude".to_string(), prelude);
// ct.1: enforce the canonical-form rule on Type::Con and
// Term::Ctor.type_name. Runs before class-schema validation
// so a stale bare cross-module ref fires the canonical-form
// diagnostic instead of a downstream one.
validate_canonical_type_names(&modules)?;
// Iter 22b.2: class-schema validation runs before registry
// construction so that ill-kinded class definitions are rejected
// before any instance against them is registered.
@@ -1796,25 +1802,30 @@ mod tests {
}
}
/// Iter 22b.2: a class whose parameter `f` appears in applied
/// position (`Type::Con { name == "f", args.len() > 0 }`) inside
/// a method signature must fire `KindMismatch`. Decision 11 axis
/// 5 forbids HKTs — class params are kind `*` only, never
/// constructors.
/// ct.1: a class whose parameter `f` appears as a `Type::Con`
/// name (the malformed-but-historically-test-fixture shape used
/// to trigger `KindMismatch` pre-ct.1) is now caught earlier by
/// the canonical-type-names validator: `f` is bare,
/// non-primitive, and not a TypeDef in the owning module, so
/// `BareCrossModuleTypeRef` fires before `validate_classdefs`
/// gets a chance to run. The `KindMismatch` path stays in the
/// codebase as dead-but-defensive code; a future tidy may
/// retire it.
#[test]
fn class_param_in_applied_position_fires_kind_mismatch() {
fn class_param_in_applied_position_fires_canonical_form_rejection() {
let entry = std::path::PathBuf::from(
"../../examples/test_22b2_kind_mismatch.ail.json",
);
let err = load_workspace(&entry)
.expect_err("must fire kind-mismatch");
.expect_err("must fire canonical-form rejection");
match err {
WorkspaceLoadError::KindMismatch { class, param, method, .. } => {
assert_eq!(class, "Functor");
assert_eq!(param, "f");
assert_eq!(method, "fmap");
WorkspaceLoadError::BareCrossModuleTypeRef { module, name, .. } => {
assert_eq!(module, "test_22b2_kind_mismatch");
assert_eq!(name, "f");
}
other => panic!("expected KindMismatch, got {other:?}"),
other => panic!(
"expected BareCrossModuleTypeRef (validator now fires first), got {other:?}",
),
}
}