Type-check the operator precedence table #52

Merged
jacksonopp merged 6 commits from us5/type-check-operator-precedence into main 2026-09-10 19:02:30 +00:00
Owner

Closes #5.

Summary

  • Type-checks Expr::Binary/Expr::Unary across the full operator set: arithmetic (+ - * / % **), ordering (< <= > >=), equality (== !=), logical (&& ||), and unary (- ! &).
  • New DiagnosticKind variants: BinaryOpMismatch (operands disagree), InvalidBinaryOpType/InvalidUnaryOpType (operands agree but the operator isn't defined for that type).
  • Shared check_matching_operand_binary helper (parameterized by a return-type override and an allowed-operand predicate) covers every binary group that needs "operands must agree, and the shared type must be valid" — bundled via a BinaryOperand struct to stay under clippy's argument-count lint.
  • Eq/Ne accept Int | Float | Bool | String (equality needs no new semantics); ordering stays Int | Float only (string ordering/concat are undecided in syntax-notes.md, deliberately deferred).
  • RangeEx/RangeInc and UnaryOp::PointerRef stay silent (None, no diagnostic) — no Ty::Range/pointer type exists yet, consistent with how every other not-yet-checked Expr variant is treated.
  • Full unit test coverage per operator group, including the "operand already failed, don't pile on a second diagnostic" propagation rule and the deliberate silent-None cases.
  • docs/type-checker-design.md gets a new ## Issue #5 section documenting these decisions (docs/syntax-status.md is lexer/parser-scoped only, per its own header, so it wasn't touched).

Test plan

  • cargo test --workspace
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01WNg6dnsh1WPghP4FuNHThj

Closes #5. ## Summary - Type-checks `Expr::Binary`/`Expr::Unary` across the full operator set: arithmetic (`+ - * / % **`), ordering (`< <= > >=`), equality (`== !=`), logical (`&& ||`), and unary (`- ! &`). - New `DiagnosticKind` variants: `BinaryOpMismatch` (operands disagree), `InvalidBinaryOpType`/`InvalidUnaryOpType` (operands agree but the operator isn't defined for that type). - Shared `check_matching_operand_binary` helper (parameterized by a return-type override and an allowed-operand predicate) covers every binary group that needs "operands must agree, and the shared type must be valid" — bundled via a `BinaryOperand` struct to stay under clippy's argument-count lint. - `Eq`/`Ne` accept `Int | Float | Bool | String` (equality needs no new semantics); ordering stays `Int | Float` only (string ordering/concat are undecided in `syntax-notes.md`, deliberately deferred). - `RangeEx`/`RangeInc` and `UnaryOp::PointerRef` stay silent (`None`, no diagnostic) — no `Ty::Range`/pointer type exists yet, consistent with how every other not-yet-checked `Expr` variant is treated. - Full unit test coverage per operator group, including the "operand already failed, don't pile on a second diagnostic" propagation rule and the deliberate silent-`None` cases. - `docs/type-checker-design.md` gets a new `## Issue #5` section documenting these decisions (`docs/syntax-status.md` is lexer/parser-scoped only, per its own header, so it wasn't touched). ## Test plan - [x] `cargo test --workspace` - [x] `cargo fmt --all -- --check` - [x] `cargo clippy --workspace --all-targets --all-features -- -D warnings` Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WNg6dnsh1WPghP4FuNHThj
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jacksonopp/twill!52
No description provided.