diff --git a/quest/m2/README.md b/quest/m2/README.md index 6df5a4491..1403d7b39 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -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` 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 diff --git a/quest/m2/ts-narrow-test.md b/quest/m2/ts-narrow-test.md new file mode 100644 index 000000000..f449715cd --- /dev/null +++ b/quest/m2/ts-narrow-test.md @@ -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.