Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md);
- [Async in the TypeScript translator](/quest/m2/ts-async.md) - moq-net's and kio's async code translates with Rust's lazy futures
- [Shared ownership](/quest/m2/ts-shared.md) - `Arc`/`Rc`/`Weak` keep exact counts, and locks and atomics become plain values
- [Share what the crate never changes in place](/quest/m2/ts-shared-read.md) - copies of `Copy` aggregates no one writes into in place go away, recovering #83's decode cost
- [Matches TypeScript has already narrowed](/quest/m2/ts-narrow-test.md) - an inner match on a value an outer match decided passes `tsc`
- [Default comparison methods](/quest/m2/ts-cmp-defaults.md) - inherited `ne`, `lt`, `le`, `gt`, `ge` and `[u8]` equality translate
- [Copy-on-write strings](/quest/m2/ts-cow-str.md) - `Cow<str>` translates, finishing `ietf/namespace.rs`
- [str slicing and &str patterns](/quest/m2/ts-str-slice.md) - `&s[a..b]` and `&str` patterns translate, so `rfind`'s offsets are usable
Expand Down
21 changes: 21 additions & 0 deletions quest/m2/ts-narrow-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# [S] Matches TypeScript has already narrowed

## Goal

rust2-ts's output passes `tsc` when a value is matched again where an enclosing match
already decided its variant, such as `match x { Dot => match x { Line(..) => .. } }` or a
match on a copy taken inside the arm, proven by differential tests against native Rust
that also type-check.

## Plan

Found by [#100](https://github.com/kixelated/rust2/pull/100) on 2026-10-27, which widens
a local TypeScript narrows by construction but not one it narrows by a test. The inner
test fails `tsc` (TS2367) rather than miscompiling.

- Fold away a test an enclosing test already decided, so the inner match lowers to its
one reachable arm.
- Where folding can't reach, such as a copy matched in the arm, widen the copy as #100
widens a constructed local.

Public API: the translator's output.