bcd41810f4
Reader-facing prose and rustdoc carried opaque shorthand like
"Decision 10", "clause-5", "mq.1", "ct.1", "eob.1", "rpe.1",
"post-mq.3", and "Iter 22b.1:" with no in-repo definition the reader
could follow. This commit replaces every such occurrence in the
durable tier the reader is most likely to land on (design/ ledger +
source //! module headers + the central /// public-item rustdoc) with
an inline content phrase plus, where applicable, a Markdown link to
the file that defines the referenced concept.
design/ ledger — 16 files:
Definition-site headings demoted from "Decision N: <title>" to
"<title>": authoring-surface, tail-calls, memory-model section in
rc-uniqueness.md, dual-allocator section, typeclass design,
effects "pure core + algebraic effects".
Cross-reference sites: "Decision 1" -> canonical-schema principle
(data-model); "Decision 3/4" -> effects + scope-boundaries; "Decision
6" -> authoring-surface; "Decision 8" -> tail-calls; "Decision 9" ->
rc-uniqueness (dual-allocator); "Decision 10" -> memory-model;
"Decision 11" -> typeclasses (model). "clause-5" -> body-link
durability gate. "clause-3" (in language-constraints) ->
bug-class-reintroduction discriminator. "mq.1/2/3", "ct.1/4",
"eob.1", "rpe.1" -> the canonical-form rule / the type-driven
dispatch / the Str carve-out / etc. "post-mq.3" -> "type-driven".
design/contracts/feature-acceptance.md: file-local "clauses 1/2/3"
-> "criteria 1/2/3" (sprachliche Kohärenz mit der File-Überschrift
"Feature-acceptance criterion"); "the clause-3 mechanism" -> "the
bug-class-reintroduction discriminator".
Source //! module headers — 24 files:
Stripped "Iter X.Y:" prefixes and "(Decision N)" / "(mq.X)" tags
from spec_drift, uniqueness, reuse_shape, migrate_canonical_types,
typeclass_22b{2,3,c}, suppress_filter, lift, mono, linearity,
diagnostic, method_dispatch_pin, method_collision_pin,
no_per_type_print_ops, mq3_multi_class_e2e, print_mono_body_shape,
print_no_leak_pin, cli_diag_human_workspace_load_error,
ct1_check_cli, prose snapshot, unbound_in_instance_method_pin,
mono_xmod_ctor_pattern, desugar.
Central /// public-item rustdoc:
ast.rs (full sweep — every "Iter X" + "Decision N" prefix
reformulated; mode/Type::Fn rustdoc now points at memory-model.md;
Constraint / SuperclassRef / InstanceDef / ClassDef rustdoc points
at typeclasses contract).
diagnostic.rs (all "(Iter X)" / "(mq.X)" tags on diagnostic codes
removed).
lib.rs (FORM_A_SPEC rustdoc points at authoring-surface.md
instead of "Decision 6").
canonical.rs (type_hash + Float-literal rustdoc).
Still outstanding (for a follow-up commit): ~500 inline `//`
code-body comments with `Iter X.Y` markers across the workspace, and
a handful of `///` rustdoc items in hash_pin / workspace_pin / lift /
mono / suppress_filter test-pin and internal-function bodies. Code
identifiers (test filenames like `mq3_multi_class_e2e.rs`, function
names like `iter18e_drop_iterative_default_preserves_hashes`) stay
verbatim per the user's "code identifiers stay verbatim" rule.
Tests: design_index_pin 5/5 + docs_honesty_pin 5/5; workspace builds
clean; full `cargo test --workspace` previously green (every
`test result: ok` line, no FAILED line).
138 lines
5.7 KiB
Rust
138 lines
5.7 KiB
Rust
//! RED-pin for the instance-method-body unbound-var bug observed in
|
|
//! the 2026-05-13 fieldtest of milestone-24 (Form-A authoring).
|
|
//!
|
|
//! Property protected: `check_def` walks `Def::Instance` method bodies
|
|
//! through the same identifier-resolution path as `Def::Fn` bodies, so
|
|
//! an unbound identifier inside an instance-method lambda body fires
|
|
//! `[unbound-var]` at `ail check`, with exit code 1, BEFORE the
|
|
//! monomorphisation pass runs. Without this, an unbound identifier
|
|
//! inside an instance-method body slips past `ail check` (false-OK)
|
|
//! and surfaces later at `ail build` as a degraded internal-error
|
|
//! diagnostic ("monomorphise_workspace: unknown identifier: <name>"),
|
|
//! with no source location, no symbol kind, and no "did you mean ...?".
|
|
//!
|
|
//! Pre-fix observed behaviour (the bug):
|
|
//! - `ail check` exits 0 with `ok (23 symbols across 2 modules)`.
|
|
//! - `ail build` exits 1 with
|
|
//! `Error: monomorphise_workspace: unknown identifier: \`format_label\``.
|
|
//!
|
|
//! Post-fix expected behaviour:
|
|
//! - `ail check` exits 1 with an `[unbound-var]` error naming
|
|
//! `format_label`. The mono pass never runs because check fails first.
|
|
//!
|
|
//! Root cause (from debugger Phase 1-2):
|
|
//! `crates/ailang-check/src/lib.rs::check_def` early-returns `Ok(())`
|
|
//! for `Def::Class | Def::Instance` (the comment claims body
|
|
//! typechecking landed alongside the typeclass-typecheck arms, but
|
|
//! the body-walk was never wired). Only the workspace-load coherence
|
|
//! checks
|
|
//! (Orphan/Duplicate/MissingMethod) in `workspace::build_registry`
|
|
//! touch instance defs, and those only inspect the schema, not the
|
|
//! method-body identifier graph.
|
|
//!
|
|
//! Fixture: `examples/bug_unbound_in_instance_method.ail`. The fixture
|
|
//! uses `format_label` (NOT a builtin) inside an instance-method lambda;
|
|
//! `int_to_str` IS a builtin and is correctly resolved. The fixture
|
|
//! parses cleanly — the only error is the unbound `format_label` in the
|
|
//! method body.
|
|
|
|
use std::path::Path;
|
|
use std::process::Command;
|
|
|
|
fn ail_bin() -> &'static str {
|
|
env!("CARGO_BIN_EXE_ail")
|
|
}
|
|
|
|
/// RED today: `ail check` on `bug_unbound_in_instance_method.ail`
|
|
/// must exit non-zero and emit `[unbound-var]` naming `format_label`,
|
|
/// matching the diagnostic shape produced at fn-body level.
|
|
///
|
|
/// Pre-fix, this test fails because `ail check` exits 0 and prints
|
|
/// `ok (23 symbols across 2 modules)`.
|
|
#[test]
|
|
fn check_fires_unbound_var_for_format_label_in_instance_method_body() {
|
|
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
|
let workspace = Path::new(manifest_dir).parent().unwrap().parent().unwrap();
|
|
let src = workspace
|
|
.join("examples")
|
|
.join("bug_unbound_in_instance_method.ail");
|
|
assert!(
|
|
src.exists(),
|
|
"fixture missing: {} — RED test requires the .ail fixture in working tree",
|
|
src.display()
|
|
);
|
|
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", src.to_str().unwrap()])
|
|
.output()
|
|
.expect("ail check failed to spawn");
|
|
let code = output.status.code().expect("process terminated by signal");
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
let combined = format!("STDOUT:\n{stdout}\nSTDERR:\n{stderr}");
|
|
|
|
assert_ne!(
|
|
code, 0,
|
|
"ail check must exit non-zero for an unbound identifier inside \
|
|
an instance-method body; got exit 0. {combined}"
|
|
);
|
|
assert!(
|
|
combined.contains("unbound-var"),
|
|
"ail check must emit diagnostic code `unbound-var`; \
|
|
got: {combined}"
|
|
);
|
|
assert!(
|
|
combined.contains("format_label"),
|
|
"diagnostic must name the unbound identifier `format_label`; \
|
|
got: {combined}"
|
|
);
|
|
assert!(
|
|
!combined.contains("monomorphise_workspace"),
|
|
"the degraded mono-pass diagnostic must NOT surface — \
|
|
`ail check` should reject the program before mono runs; \
|
|
got: {combined}"
|
|
);
|
|
}
|
|
|
|
/// Companion RED: also assert the `--json` shape. The fn-body level
|
|
/// already emits `{"severity":"error","code":"unbound-var"}` via
|
|
/// `check_json_unbound_var` in `e2e.rs`; the instance-method-body
|
|
/// path must produce the same structured shape.
|
|
#[test]
|
|
fn check_json_unbound_var_in_instance_method_body() {
|
|
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
|
let workspace = Path::new(manifest_dir).parent().unwrap().parent().unwrap();
|
|
let src = workspace
|
|
.join("examples")
|
|
.join("bug_unbound_in_instance_method.ail");
|
|
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", src.to_str().unwrap(), "--json"])
|
|
.output()
|
|
.expect("ail check --json failed to spawn");
|
|
let code = output.status.code().expect("process terminated by signal");
|
|
let stdout = String::from_utf8_lossy(&output.stdout).into_owned();
|
|
let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
|
|
let combined = format!("STDOUT:\n{stdout}\nSTDERR:\n{stderr}");
|
|
|
|
assert_eq!(
|
|
code, 1,
|
|
"ail check --json must exit 1; got {code}. {combined}"
|
|
);
|
|
|
|
// Stdout must be a JSON array containing at least one
|
|
// unbound-var error diagnostic.
|
|
let diags: serde_json::Value = serde_json::from_str(stdout.trim())
|
|
.unwrap_or_else(|e| panic!("stdout must be JSON; parse error: {e}; got: {stdout}"));
|
|
let arr = diags.as_array().expect("diagnostics must be a JSON array");
|
|
assert!(
|
|
arr.iter().any(|d| {
|
|
d.get("severity").and_then(|v| v.as_str()) == Some("error")
|
|
&& d.get("code").and_then(|v| v.as_str()) == Some("unbound-var")
|
|
&& d.to_string().contains("format_label")
|
|
}),
|
|
"expected an error diagnostic with code `unbound-var` naming \
|
|
`format_label`; got: {stdout}"
|
|
);
|
|
}
|