iter 22b.2.9: missing-constraint per-fn diagnostic
This commit is contained in:
@@ -127,3 +127,45 @@ fn class_method_entry_carries_full_metadata() {
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Property protected: a polymorphic FnDef that calls a class method
|
||||
/// (e.g. `show x` where `x: a`) but does not declare the matching class
|
||||
/// constraint in its `Forall.constraints` MUST receive a
|
||||
/// `missing-constraint` diagnostic. This is the principal soundness
|
||||
/// guarantee of class-method calls inside polymorphic functions: every
|
||||
/// dispatch point at a polymorphic type must be backed by an in-scope
|
||||
/// constraint that the caller will eventually have to satisfy. Without
|
||||
/// this check, monomorphisation in 22b.3 would have no way to know
|
||||
/// which dictionary to thread.
|
||||
#[test]
|
||||
fn fn_calling_class_method_without_declared_constraint_fires_missing_constraint() {
|
||||
let entry = examples_dir().join("test_22b2_missing_constraint.ail.json");
|
||||
let ws = ailang_core::workspace::load_workspace(&entry)
|
||||
.expect("workspace loads");
|
||||
let diagnostics = ailang_check::check_workspace(&ws);
|
||||
assert!(
|
||||
diagnostics.iter().any(|d| d.code == "missing-constraint"),
|
||||
"expected missing-constraint; got: {:?}",
|
||||
diagnostics.iter().map(|d| &d.code).collect::<Vec<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
/// Property protected: when a polymorphic FnDef declares the matching
|
||||
/// class constraint in its `Forall.constraints`, the call to the class
|
||||
/// method typechecks clean — the residual constraint produced at the
|
||||
/// call site is satisfied by the in-scope declared constraint, and no
|
||||
/// diagnostic fires. This is the positive counterpart to the
|
||||
/// missing-constraint check: declaring `Show a =>` makes `show x`
|
||||
/// well-formed inside the body.
|
||||
#[test]
|
||||
fn fn_with_correct_constraint_typechecks_green() {
|
||||
let entry = examples_dir().join("test_22b2_constraint_declared.ail.json");
|
||||
let ws = ailang_core::workspace::load_workspace(&entry)
|
||||
.expect("workspace loads");
|
||||
let diagnostics = ailang_check::check_workspace(&ws);
|
||||
assert!(
|
||||
diagnostics.is_empty(),
|
||||
"expected no diagnostics; got: {:?}",
|
||||
diagnostics
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user