0%

§04 Diagnostics — capset error codes

Goal

Wire structured diagnostics for capset-validation failures via the E1xxx parser/typeck range per impl-hygiene.md §Error Handling.

Implementation Sketch

Error codes are stable API. Each goes through ori_diagnostic::ErrorCode with a fixed integer + name + message template. Construction sites in §03 typeck use Diagnostic::error(code).with_message(...).with_label(span, ...).with_help(...) per impl-hygiene.md §Error Handling — never format!() strings inline.

Per diagnostic.md §Message Style: messages name what failed, where, and what to do. Examples:

E1221: capset `Net` declares no members
  --> file.ori:5:8
   |
 5 | capset Net =;
   |        ^^^ empty capset
   = help: a capset must contain at least one capability or other capset
E1222: capset cycle detected: `A` → `B` → `A`
  --> file.ori:3:8
   |
 3 | capset A = B;
   |        ^ part of the cycle
   |
   ::: file.ori:5:8
   |
 5 | capset B = A;
   |        ^ closes the cycle
   = help: capsets cannot reference themselves transitively

Implementation Items

  • Allocate E1221 / E1222 / E1223 / E1224 in compiler_repo/compiler/ori_diagnostic/src/error_code/mod.rs. Sibling reference: nearby existing E12xx codes for capability validation (locate via grep -n 'E12' compiler_repo/compiler/ori_diagnostic/src/error_code/mod.rs).
  • Define error-message templates with structured fields (capset name, cycle path, offending member).
  • Implement did you mean? Damerau-Levenshtein suggestion for E1221 when sibling capsets exist (per impl-hygiene.md §Error Handling edit-distance rule).
  • Multi-span emission for E1222 cycle errors — primary label at the cycle root, secondary labels at each cycle edge.
  • Wire construction sites in §03 typeck modules (registration/capsets.rs, capabilities.rs).
  • Rust Tests: compiler_repo/compiler/ori_diagnostic/src/error_code/tests.rs — assert each E12xx code has a stable name + message template; assert format() output matches expected for each error.

Spec References

  • Proposal §Validation.
  • diagnostic.md §Message Style — diagnostic format.
  • impl-hygiene.md §Error Handling — structured construction, error code stability.

Tests

  • Rust unit tests for error code registration + format output (this section).
  • Spec tests at §05 produce real-world error scenarios + assert error codes via #compile_fail("E1221") annotations.

Intelligence Reconnaissance

scripts/intel-query.sh symbols "E12" --repo ori --kind constant --limit 20 to inventory adjacent error codes and avoid collisions. scripts/intel-query.sh similar "cycle_error" --repo rust,swift,koka --limit 5 for prior-art cycle-error message shapes.