Repository navigation
An optional parameter fits an overload as the type it holds - #716
Merged
Merged
Conversation
`new Array<int>(10)` against DefaultLib's Array<T> constructors `(count: int = 0)` and `(...args: T[])` went to the rest constructor (length 1): overloadArgumentFit scored the defaulted parameter as optional<si32>, which an int reached only by conversion (1), against the rest element's exact match (3). The optional is now stripped before scoring, so both fit exactly and the one declared first wins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An optional parameter fits an overload as the type it holds
new Array<int>(10)(and, since #715,new Array(10)) against DefaultLib'sArray<T>constructors
(count: int = 0)and(...args: T[])made a one-element array: the restconstructor won.
resolveConstructorOverloadscores each constructor withoverloadArgumentFit. Thedefaulted
countis typed!ts.optional<si32>, which anintargument reached only byconversion (1), while the rest element
intwas an exact match (3). The optional is nowstripped before scoring, so both fit exactly and the tie goes to the constructor declared
first,
(count: int).overloadArgumentFitalso picks among a@cppclass's overloaded methods; there too anoptional parameter now fits as the type it holds.
Tests
00class_constructor_overloads.ts:C<T>with(count: int = 0)and(...args: T[]);new C<int>(10)ran the rest constructor before the fix.tests.ps1(with the uncommittedArray<T>constructors): gc, rc, none, ownpass in all four passes;
new Array<int>(10)andnew Array(10)have length 10.Not in this PR
-mm=own:new Array<string>("a", "b")through the rest constructor fails the ownchecker (
find/findLast/_with);new Array<string>(["a", "b"])works.🤖 Generated with Claude Code