Type-check function signatures, calls, and return types #49

Merged
jacksonopp merged 2 commits from us3/type-check-function-signatures into main 2026-09-02 01:37:58 +00:00
Owner

Closes #3.

Migrates Ty to #[salsa::interned] (as Ty/TyKind) ahead of schedule so Ty::Fn { params, ret } has somewhere cheap to live, then implements:

  • Expr::Fn checking: resolves each param's declared type (falling back to a new TyKind::Error(Symbol) placeholder on failure, so a bad param type doesn't cascade into UndefinedVariable for every reference to it in the body), binds params into a fresh scope frame, checks the body in that scope, and compares the body's inferred type against the declared return type (ReturnTypeMismatch).
  • Expr::Call checking: resolves the callee, verifies it's a TyKind::Fn (NotCallable otherwise), checks arity (ArityMismatch) before pairing arguments against declared param types (ArgumentTypeMismatch, spanned at the offending argument).
  • New check_type_expr helper, factoring the "resolve or push the right diagnostic" logic out of check_let so Expr::Fn's param/return resolution can share it.

Expr::BracketCall and Param::SelfParam stay unhandled, per the design doc's explicit scope decision for this issue.

Unit tests added in ty.rs and end-to-end tests in queries.rs for all of the above. docs/type-checker-design.md updated throughout with the design decisions.

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

Closes #3. Migrates `Ty` to `#[salsa::interned]` (as `Ty`/`TyKind`) ahead of schedule so `Ty::Fn { params, ret }` has somewhere cheap to live, then implements: - `Expr::Fn` checking: resolves each param's declared type (falling back to a new `TyKind::Error(Symbol)` placeholder on failure, so a bad param type doesn't cascade into `UndefinedVariable` for every reference to it in the body), binds params into a fresh scope frame, checks the body in that scope, and compares the body's inferred type against the declared return type (`ReturnTypeMismatch`). - `Expr::Call` checking: resolves the callee, verifies it's a `TyKind::Fn` (`NotCallable` otherwise), checks arity (`ArityMismatch`) before pairing arguments against declared param types (`ArgumentTypeMismatch`, spanned at the offending argument). - New `check_type_expr` helper, factoring the "resolve or push the right diagnostic" logic out of `check_let` so `Expr::Fn`'s param/return resolution can share it. `Expr::BracketCall` and `Param::SelfParam` stay unhandled, per the design doc's explicit scope decision for this issue. Unit tests added in `ty.rs` and end-to-end tests in `queries.rs` for all of the above. `docs/type-checker-design.md` updated throughout with the design decisions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115F8iYbo8n1xSxxQP4scjZ
jacksonopp deleted branch us3/type-check-function-signatures 2026-09-02 01:37:58 +00:00
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!49
No description provided.