Skip to content

new of a generic class: specialize by the defaults only when nothing infers the type arguments - #694

Merged
ASDAlexander77 merged 1 commit into
mainfrom
new-generic-default-instantiation
Oct 26, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
new-generic-default-instantiation

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

new Set([1, 2]) made all of Set<any> (its default, Set<V = any>) beside the Set<si32> the constructor's arguments infer: new specialized the class name by its default type arguments before inference and the receiver were tried. Every model compiled the extra class; under -mm=own its methods fail (any elements), so every untyped Set failed to compile.

Now, without type arguments but with constructor arguments or a receiver type, the name is resolved unspecialized, and the defaults apply only when neither gives the type arguments. Unchanged: new Box() is still Box<any>, const c: Box<string> = new Box() is still Box<string>, explicit type arguments as written.

Tests

  • New: test-generic-class-inference-no-default-specialization (IR check on 00generic_class_constructor_inference: no Pairs<any, any> beside Pairs<string, si32>).
  • Windows release ctest: 5825/5825.
  • DefaultLib suite (AOT release): gc 168/168; own 87 → 97, none newly failing (all set_* tests now pass; the map_* ones still failing use an untyped new Map() with mixed keys, genuinely Map<any, any>).

Also updates the -mm=own guide's limits and the own containers spec note.

🤖 Generated with Claude Code

…infers the type arguments

`new Set([1, 2])` made all of Set<any> (its default, `Set<V = any>`) beside the Set<si32> the
constructor's arguments infer: the name was specialized by its defaults before the inference and
the receiver were tried. Every model compiled the extra class; under -mm=own its methods failed
(`any` elements), so every untyped Set failed to compile.

Now, without type arguments but with constructor arguments or a receiver type, the name is resolved
unspecialized, and the defaults apply only when neither gives the type arguments (`new Set()`).

Test: test-generic-class-inference-no-default-specialization (no Pairs<any, any> in
00generic_class_constructor_inference).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 5845867 into main Oct 26, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the new-generic-default-instantiation branch October 26, 2026 17:24
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