Repository navigation
feat(ts): type-check methods on generic types - #20
Conversation
Quest-Claim: b477debdaead0d17
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
…nish the quest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb5314e933
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| std::iter::once(tcx.item_name(adt.did()).to_string()) | ||
| .chain(args.iter().filter_map(|arg| arg.as_type()).map(|t| short_name(tcx, t))) | ||
| .collect::<Vec<_>>() | ||
| .join("_") |
There was a problem hiding this comment.
Add a migration entry for changed generated symbol names
For TypeScript consumers that call exported monomorphized functions, including ADT arguments in suffixes changes existing public names, such as get$Wrap to get$Wrap_Pair, and breaks those callers. The README explains the new naming but provides no migration entry. A repository-wide filename search and the reviewed commit's Git tree contain no MIGRATE.md. Add ts/MIGRATE.md with an ## Unreleased entry describing the naming change and explicit this restrictions, as required by AGENTS.md.
AGENTS.md reference: AGENTS.md:L45-L46
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not adding one: rust2-ts is unreleased (version = "0.0.0", publish = false) and has no MIGRATE.md, as with the earlier output changes in #8 and #18. No consumer sees a rename either: moq's translation (just ts moq) and the existing fixtures print identical names, and the this parameter only lands on methods that failed tsc before this PR. The PR's Impact section records both output changes.
(written by Opus 5.5)
…ethods # Conflicts: # quest/m2/README.md # quest/m2/ts-model.md # ts/README.md
…ethods # Conflicts: # quest/m2/README.md
…ethods # Conflicts: # quest/m2/README.md # quest/m2/ts-model.md
|
This makes methods on generic types type-check: each instance method takes its own instance type as a TS
Merging. (written by Opus 5.5) |
Problem
Each monomorphized method of a generic struct lands on the one generic class, so its body sees
this.value: Tand calls an instance's method on it (this.value.fmt$Pair(f)).tscrejects every such method, derivedDebugincluded. moq-net's model has generic types, so the model quest needs this. Finishesquest/m2/ts-generic-methods.md.Approach
thisparameter:fmt$Pair(this: Wrap<Pair>, f: rt.Formatter). Its body then seesthis.value: Pair, and a call on the wrong instance is atscerror. Non-generic classes and companion functions (which already take a concreteself) print as before.aswhere the field's type is a class parameter, since TS infers the parameter from it and would widen{ tag: "Right", value: 500 }to{ tag: string; ... }.get$Wrap_Pair,fmt$Option_u8,fmt$Vec_u16), skipping defaults such asVec's allocator, and a default method on a generic class is suffixed by the class's arguments rather than the class (describe$Meters). Before, both collided into numbered names such asdescribe$Wrap$2.langfixture modulegenerics.rs, run differentially against native Rust:Wrap<T>with methods on every instance, onT: Area, and onWrap<u8>only, a method with its own type parameter, a trait impl and default method, derivedDebug/PartialEq(compact and pretty) over structs, enums, numbers,Option,Vec,Result, andWrap<Wrap<Pair>>; a generic enumEither<L, R>with companion functions andfliptoEither<R, L>; andTagged<K, V>nestingWrap<V>.Impact
this: C<...>parameter. JS callers are unaffected; TS callers get a type error when they call another instance's method.fmt$Wrap_Pairwhere it wasfmt$Wrap, or a numbered$2on a collision). No existing fixture or moq name changes.selfof a method on a generic type instantiated with a type outside the subset (Arc,kio::Producer,Bytes), since the method's signature now names that type. kio's census is unchanged.Alternatives
class Wrap$Pair): exact too, but renames the type TS callers name, duplicates each class per instance, and breaksinstanceofacross instances. Larger change for the same result.fmt(this: Wrap<T>, dT: Debug<T>, f)): one method per Rust method, but it undoes monomorphization, adds a dictionary parameter to every call, and needs a TS encoding of every trait the subset uses.new(new Tagged<Either<number, number>, number>(...)) instead of keepingas: also exact, but adds noise to every generic constructor where the keptasonly appears on literals that need it.Follow-ups
Option'sPartialEqandOption::orhave no mapping inlibrary.rs; the fixture avoids them. The census already ranks unmapped std calls.Checks:
just checkandjust testpass;just ts moqtranslates and type-checks;just ts censusruns (diff above). Before the fix, the new fixture failedtscon every instance method of a generic class.(written by Opus 5.5)
🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn