Skip to content

Infer a generic class from overloaded and rest constructors; test the default library under every model - #715

Merged
ASDAlexander77 merged 1 commit into
mainfrom
generic-ctor-overload-inference
Oct 28, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
generic-ctor-overload-inference

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Generic class inferred through overloaded and rest constructors

new Array(10, 20, 30), against DefaultLib's Array<T> with three constructors
(data: T[] = [], count: int = 0, ...args: T[]), stayed the unspecialized Array
("Class member 'length' can't be found"). inferClassTypeFromConstructorArguments:

  • gave up on any class with more than one constructor;
  • skipped rest parameters.

It now tries the constructors that can take that many arguments, in declaration order;
a rest parameter takes T from every argument it collects; the first constructor that
gives every type argument answers. new Array(10, 20, 30) is Array<si32>.

Test: List<T> (array constructor + rest constructor) added to
00generic_class_constructor_inference.ts; it fails without the fix.

CI: default library tests under every memory model

The library was built for gc, rc, none and own, but Test Default Library ran only gc.
Both steps (Windows tests.ps1, Linux tests.sh) now run each model; on Windows each in
its own pwsh, since tests.ps1 reads the library paths once at its start. Every model
runs before a failure fails the step.

Verification

  • ctest Release: 6082/6082 passed.
  • DefaultLib tests.ps1 locally (with DefaultLib's uncommitted Array<T> constructors and
    the new array_constructors_overload.ts): gc, rc, none, own all pass in all four passes.
  • Linux rc/none/own have not run in CI before; this PR is their first run.

Not in this PR

  • new Array<int>(10) (and so new Array(10)) has length 1: with T = int the call picks
    (...args: T[]) over (count: int).
  • -mm=own: new Array<string>("a", "b") through the rest constructor fails the own checker
    (find/findLast/_with); new Array<string>(["a", "b"]) works.

🤖 Generated with Claude Code

…I tests the default library under every model

`new Array(10, 20, 30)` against DefaultLib's Array<T> with three constructors
(`data: T[]`, `count: int`, `...args: T[]`) stayed the unspecialized Array:
inferClassTypeFromConstructorArguments gave up on any class with more than one
constructor, and skipped rest parameters. It now tries the constructors that can
take that many arguments in declaration order, takes T from every argument a
rest parameter collects, and the first that gives every type argument answers.

CI built the default library for gc, rc, none and own but tested only gc: the
Test Default Library steps (Windows and Linux) now run tests.ps1 / tests.sh for
each model, every model before a failure fails the step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit b9212b0 into main Oct 28, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the generic-ctor-overload-inference branch October 28, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant