0%

Type checker: invariant analysis + diagnostics

Goal

Pattern checked against scrutinee exactly as a match arm; the [: type] annotation ascribes the SCRUTINEE. Error-preservation invariant: compute per shape whether a live Err can occupy the mismatch region (top-level or any inspected nested Result position; or/at patterns evaluated over the whole-pattern union); violating shapes are compile errors with exact suggested forms. None-propagation context typing mirrors ? (16.5.2 + try boundary). Plain let/E2001 behavior stays byte-identical (Resolution A untouched).

Implementation Sketch

Scope contract: the approved proposal (compiler_repo/docs/ori_lang/proposals/approved/fallible-let-binding-proposal.md) - Design + Semantics + Spec & Grammar Impact sections govern this section verbatim; no scope invention. TDD: the failing test matrix for this section’s shapes lands before implementation; debug AND release verified at close.

Spec References

  • compiler_repo/docs/ori_lang/proposals/approved/fallible-let-binding-proposal.md
  • compiler_repo/docs/ori_lang/v2026/spec/16-control-flow.md (16.0.3, 16.5, 16.6, 16.7)
  • compiler_repo/docs/ori_lang/v2026/spec/15-patterns.md; 13-variables.md; grammar.ebnf

Work Items

  • Check fallible_pattern against the scrutinee; annotation ascribes scrutinee; or-pattern binding consistency incl. $-marker agreement
  • Implement the error-preservation invariant (mismatch-region Err detection, nested Result positions, or/at union analysis) with per-shape errors carrying exact suggested forms
  • Propagation-context typing: None carrier must be absorbable by the enclosing function or try boundary, reusing ? context diagnostics
  • Diagnostics: E2001 gains the let? help line; irrefutable-let? warning; redundant bare Some(binding) warning; $-constant-shadow warning with match-guard help
  • Typeck tests incl. a byte-identical pin on plain-let E2001 output