fix(resolve): a plain constructor parameter names an inherited field only when passed to super
Merged
BO
2mo ago+95+95+01234567890123456789-2-2-0123456789
Follow-up to #450, which left one case open (CodeRabbit finding on that PR).
Problem. In a class that extends another, any typed constructor parameter was taken for an inherited field, even when the constructor never passed it on. class B extends A { constructor(req: Request) { super(); } } made this.req.header() resolve to Request.header.
Change. The constructor's own body is read; a plain parameter counts only when it is an argument of super(...). super(options.req) does not count. Parameter properties (private req: T) and this.req = new T are unchanged.
Checks.
- Two new cases in
field-chain-owner.test.ts(nothing passed to super; a member of another value passed). With the check disabled they fail withexpected [ 'Mailer::send' ] to deeply equal []; with it they pass. The existing "plain constructor parameter handed to super" case still passes. - Kernel build with clippy
-D warningsclean. - Full suite: 688 files, 8774 tests passed, 39 skipped. No golden dump changed.
- Not measured: hono and zod oracle recall. The rest of #450's measurement setup was not rebuilt for this change.
Summary by cubic
Fixes derived-class resolution so a plain constructor parameter only names an inherited field when the constructor hands it directly to super(...).
super(options.req),super(wrap(mailer)),super({ mailer }), and asuper()inside a string literal no longer count; only a bare, top-level argument passed tosuper(...)does.- The scan reads the constructor body, blanks out string and template literal contents, and matches arguments at depth one.
- Parameter properties (
private req: T) andthis.req = new Tassignments behave as before. - Adds test cases covering constructors that forward nothing, a member of another value, an argument wrapped in a call, an object property, and a super call inside a string literal.
Summary by CodeRabbit
- Bug Fixes
- Improved TypeScript inherited-field detection for derived classes. A constructor parameter is recognized as an inherited field only when passed as a bare, top-level argument to
super(...). Passing it as a property, wrapping it in another call, or merely mentioning it in a string or template literal does not qualify, preventing calls from being incorrectly associated with that parameter’s type.
- Improved TypeScript inherited-field detection for derived classes. A constructor parameter is recognized as an inherited field only when passed as a bare, top-level argument to