check if/else expressions #63

Merged
jacksonopp merged 4 commits from us54/check-if-else into main 2026-09-16 18:35:40 +00:00
Owner

Closes #54.

Type-checks Expr::If: condition must be Bool (reports InvalidConditional otherwise), both branches must agree on their result type when else is present (reports the new MismatchedElse diagnostic otherwise, resolving to the then branch's type), and the expression resolves to Unit when else is absent, mirroring Expr::Block's trailing-expr-less case.

Test plan

  • cargo test -p twill-check (new unit tests for matching branches, no-else, non-Bool cond, mismatched branches, and a failing else branch not double-reporting)
Closes #54. Type-checks `Expr::If`: condition must be `Bool` (reports `InvalidConditional` otherwise), both branches must agree on their result type when `else` is present (reports the new `MismatchedElse` diagnostic otherwise, resolving to the `then` branch's type), and the expression resolves to `Unit` when `else` is absent, mirroring `Expr::Block`'s trailing-expr-less case. ## Test plan - [x] `cargo test -p twill-check` (new unit tests for matching branches, no-else, non-`Bool` cond, mismatched branches, and a failing else branch not double-reporting)
add tests for check if/else
Some checks failed
CI / check (pull_request) Failing after 45s
8ae426dacb
formatting
Some checks failed
CI / check (pull_request) Failing after 1m25s
9c6b7bd287
clippy
All checks were successful
CI / check (pull_request) Successful in 3m36s
d336cfc5d3
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!63
No description provided.