Skip to content

✨ feat(mq-check): add dead code detection and improve type inference#1481

Merged
harehare merged 6 commits intomainfrom
feat/type-check-dead-code-detection
Mar 22, 2026
Merged

✨ feat(mq-check): add dead code detection and improve type inference#1481
harehare merged 6 commits intomainfrom
feat/type-check-dead-code-detection

Conversation

@harehare
Copy link
Copy Markdown
Owner

No description provided.

- Introduce `Type::Never` (bottom type) to represent unreachable code paths;
  `subtract()` on a union returns `Never` when all members are eliminated
- Add `TypeError::UnreachableCode` reported when a branch is provably dead:
  - then-branch: concrete variable type doesn't match the predicate
  - else-branch: all union members are exhausted by the predicate
- Fix Union-Union unification to use symmetric all-member matching,
  preventing spurious "type mismatch" errors when both sides carry the
  same union type through separate branches
- Infer `while` loop return type as `Union(body, None)` since the condition
  may be false on the first check; bare `break` contributes `None` as well
- Skip `SymbolKind::Parameter` in `detect_dead_then_branch` — parameters
  are polymorphic so predicate checks on them must not be flagged as dead
- Add comprehensive tests for dead code detection, parameter polymorphism
  (no false positives on `contains`/`map`/`flat_map`-style functions), and
  `skip_while`/`take_while` runtime behavior
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 21, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/type-check-dead-code-detection (e553485) with main (dc1f3ea)

Open in CodSpeed

@harehare harehare merged commit 332c4f4 into main Mar 22, 2026
6 checks passed
@harehare harehare deleted the feat/type-check-dead-code-detection branch March 22, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant