From a482da4c8ed2a18dae3dc3f4f1c6dd98b961627c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:09:50 -0700 Subject: [PATCH] chore(quest): matches TypeScript has already narrowed From #100's report. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- quest/m2/README.md | 1 + quest/m2/ts-narrow-test.md | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 quest/m2/ts-narrow-test.md diff --git a/quest/m2/README.md b/quest/m2/README.md index fa94622f3..bec4c3c9b 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -35,6 +35,7 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md); - [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 - [Output tsc accepts for writes through Result and Poll compares](/quest/m2/ts-tsc-shapes.md) - two shapes whose output fails `tsc` type-check +- [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.