-
Notifications
You must be signed in to change notification settings - Fork 964
Fix crash inferring constrained variadic tuples with optional elements #3943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Andarist
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
Andarist:fix/crash-tuple-implied-constraint-inference
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
200 changes: 200 additions & 0 deletions
200
...aselines/reference/compiler/inferTypesWithFixedTupleExtendsAtVariadicPosition2.errors.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| inferTypesWithFixedTupleExtendsAtVariadicPosition2.ts(112,27): error TS1257: A required element cannot follow an optional element. | ||
| inferTypesWithFixedTupleExtendsAtVariadicPosition2.ts(168,27): error TS1257: A required element cannot follow an optional element. | ||
|
|
||
|
|
||
| ==== inferTypesWithFixedTupleExtendsAtVariadicPosition2.ts (2 errors) ==== | ||
| // repro #51138 | ||
|
|
||
| type SubTup2FixedLength<T extends unknown[]> = T extends [ | ||
| ...infer B extends [any, any], | ||
| any | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2FixedLengthTest2 = SubTup2FixedLength<[a: 0]>; | ||
|
|
||
| type SubTup2Variadic<T extends unknown[]> = T extends [ | ||
| ...infer B extends [any, any], | ||
| ...any | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2VariadicTest3 = SubTup2Variadic<[a: 0, ...b: 1[]]>; | ||
| type SubTup2VariadicTest4 = SubTup2Variadic<[...a: 0[]]>; | ||
| type SubTup2VariadicTest5 = SubTup2Variadic<[a: 0, b: 1]>; | ||
|
|
||
| type SubTup2VariadicAndRest<T extends unknown[]> = T extends [ | ||
| ...infer B extends [any, any], | ||
| ...(infer C)[] | ||
| ] | ||
| ? [...B, ...[C]] | ||
| : never; | ||
|
|
||
| type SubTup2VariadicAndRestTest2 = SubTup2VariadicAndRest<[a: 0, ...b: 1[]]>; | ||
| type SubTup2VariadicAndRestTest3 = SubTup2VariadicAndRest<[...a: 0[]]>; | ||
| type SubTup2VariadicAndRestTest4 = SubTup2VariadicAndRest<[a: 0, b: 1]>; | ||
|
|
||
| type SubTup2TrailingVariadic<T extends unknown[]> = T extends [ | ||
| ...any, | ||
| ...infer B extends [any, any], | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2TrailingVariadicTest3 = SubTup2TrailingVariadic<[...a: 0[], b: 1]>; | ||
| type SubTup2TrailingVariadicTest4 = SubTup2TrailingVariadic<[...a: 0[]]>; | ||
| type SubTup2TrailingVariadicTest5 = SubTup2TrailingVariadic<[b: 1, c: 2]>; | ||
|
|
||
| type SubTup2RestAndTrailingVariadic2<T extends unknown[]> = T extends [ | ||
| ...(infer C)[], | ||
| ...infer B extends [any, any], | ||
| ] | ||
| ? [C, ...B] | ||
| : never; | ||
|
|
||
| type SubTup2RestAndTrailingVariadic2Test2 = SubTup2RestAndTrailingVariadic2<[...a: 0[], b: 1]>; | ||
| type SubTup2RestAndTrailingVariadic2Test3 = SubTup2RestAndTrailingVariadic2<[...a: 0[]]>; | ||
| type SubTup2RestAndTrailingVariadic2Test4 = SubTup2RestAndTrailingVariadic2<[b: 1, c: 2]>; | ||
|
|
||
| type SubTup2VariadicWithLeadingFixedElements<T extends unknown[]> = T extends [ | ||
| any, | ||
| ...infer B extends [any, any], | ||
| ...any | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2VariadicWithLeadingFixedElementsTest3 = SubTup2VariadicWithLeadingFixedElements<[a: 0, b: 1, ...c: 2[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElementsTest4 = SubTup2VariadicWithLeadingFixedElements<[a: 0, ...b: 1[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElementsTest5 = SubTup2VariadicWithLeadingFixedElements<[...a: 0[]]>; | ||
|
|
||
| type SubTup2VariadicWithLeadingFixedElements2<T extends unknown[]> = T extends [ | ||
| any, | ||
| any, | ||
| ...infer B extends [any], | ||
| ...any | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2VariadicWithLeadingFixedElements2Test = SubTup2VariadicWithLeadingFixedElements2<[a: 0, b: 1, c: 2, ...d: 3[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements2Test2 = SubTup2VariadicWithLeadingFixedElements2<[a: 0, b: 1, c: 2, d: 3, ...e: 4[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements2Test3 = SubTup2VariadicWithLeadingFixedElements2<[a: 0, b: 1, ...c: 2[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements2Test4 = SubTup2VariadicWithLeadingFixedElements2<[a: 0, ...b: 1[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements2Test5 = SubTup2VariadicWithLeadingFixedElements2<[...a: 0[]]>; | ||
|
|
||
| type SubTup2VariadicWithLeadingFixedElements3<T extends unknown[]> = T extends [ | ||
| any, | ||
| ...infer B extends [any, any], | ||
| ...(infer C)[] | ||
| ] | ||
| ? [B, C] | ||
| : never; | ||
|
|
||
| type SubTup2VariadicWithLeadingFixedElements3Test = SubTup2VariadicWithLeadingFixedElements3<[a: 0, b: 1, c: 2, d: 3, ...e: 4[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements3Test2 = SubTup2VariadicWithLeadingFixedElements3<[a: 0, b: 1, c: 2, ...d: 3[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements3Test3 = SubTup2VariadicWithLeadingFixedElements3<[a: 0, b: 1, ...c: 2[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements3Test4 = SubTup2VariadicWithLeadingFixedElements3<[a: 0, ...b: 1[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements3Test5 = SubTup2VariadicWithLeadingFixedElements3<[...a: 0[]]>; | ||
| type SubTup2VariadicWithLeadingFixedElements3Test6 = SubTup2VariadicWithLeadingFixedElements3<[a: 0, b: 1, c: 2]>; | ||
|
|
||
| type SubTup2VariadicWithTrailingOptionalElement<T extends unknown[]> = T extends [ | ||
| ...infer B extends [0, 1?], | ||
| ...any | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2VariadicWithTrailingOptionalElementTest = SubTup2VariadicWithTrailingOptionalElement<[a: 0]>; | ||
| type SubTup2VariadicWithTrailingOptionalElementTest2 = SubTup2VariadicWithTrailingOptionalElement<[a: 0, b: 1]>; | ||
| type SubTup2VariadicWithTrailingOptionalElementTest3 = SubTup2VariadicWithTrailingOptionalElement<[a: 0, b: 1, c: 2]>; | ||
| type SubTup2VariadicWithTrailingOptionalElementTest4 = SubTup2VariadicWithTrailingOptionalElement<[a: 0, ...b: 1[]]>; | ||
| type SubTup2VariadicWithTrailingOptionalElementTest5 = SubTup2VariadicWithTrailingOptionalElement<[...a: 0[]]>; | ||
|
|
||
| type SubTup2VariadicWithLeadingOptionalElement<T extends unknown[]> = T extends [ | ||
| ...infer B extends [0?, 1], | ||
| ~ | ||
| !!! error TS1257: A required element cannot follow an optional element. | ||
| ...any | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2VariadicWithLeadingOptionalElementTest = SubTup2VariadicWithLeadingOptionalElement<[b: 1]>; | ||
| type SubTup2VariadicWithLeadingOptionalElementTest2 = SubTup2VariadicWithLeadingOptionalElement<[a: 0, b: 1]>; | ||
| type SubTup2VariadicWithLeadingOptionalElementTest3 = SubTup2VariadicWithLeadingOptionalElement<[a: 0, b: 1, c: 2]>; | ||
| type SubTup2VariadicWithLeadingOptionalElementTest4 = SubTup2VariadicWithLeadingOptionalElement<[a: 0, ...b: 1[]]>; | ||
| type SubTup2VariadicWithLeadingOptionalElementTest5 = SubTup2VariadicWithLeadingOptionalElement<[...a: 1[]]>; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingFixedElements<T extends unknown[]> = T extends [ | ||
| ...any, | ||
| ...infer B extends [any, any], | ||
| any, | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingFixedElementsTest3 = SubTup2TrailingVariadicWithTrailingFixedElements<[...a: 0[], b: 1, c: 2]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElementsTest4 = SubTup2TrailingVariadicWithTrailingFixedElements<[...a: 0[], b: 1]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElementsTest5 = SubTup2TrailingVariadicWithTrailingFixedElements<[...a: 0[]]>; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingFixedElements2<T extends unknown[]> = T extends [ | ||
| ...any, | ||
| ...infer B extends [any], | ||
| any, | ||
| any, | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingFixedElements2Test = SubTup2TrailingVariadicWithTrailingFixedElements2<[...a: 0[], b: 1, c: 2, d: 3]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements2Test2 = SubTup2TrailingVariadicWithTrailingFixedElements2<[...a: 0[], b: 1, c: 2, d: 3, e: 4]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements2Test3 = SubTup2TrailingVariadicWithTrailingFixedElements2<[...a: 0[], b: 1, c: 2]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements2Test4 = SubTup2TrailingVariadicWithTrailingFixedElements2<[...a: 0[], b: 1]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements2Test5 = SubTup2TrailingVariadicWithTrailingFixedElements2<[...a: 0[]]>; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingFixedElements3<T extends unknown[]> = T extends [ | ||
| ...(infer C)[], | ||
| ...infer B extends [any, any], | ||
| any, | ||
| ] | ||
| ? [C, B] | ||
| : never; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingFixedElements3Test = SubTup2TrailingVariadicWithTrailingFixedElements3<[...a: 0[], b: 1, c: 2, d: 3, e: 4]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements3Test2 = SubTup2TrailingVariadicWithTrailingFixedElements3<[...a: 0[], b: 1, c: 2, d: 3]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements3Test3 = SubTup2TrailingVariadicWithTrailingFixedElements3<[...a: 0[], b: 1, c: 2]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements3Test4 = SubTup2TrailingVariadicWithTrailingFixedElements3<[...a: 0[], b: 1]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements3Test5 = SubTup2TrailingVariadicWithTrailingFixedElements3<[...a: 0[]]>; | ||
| type SubTup2TrailingVariadicWithTrailingFixedElements3Test6 = SubTup2TrailingVariadicWithTrailingFixedElements3<[b: 1, c: 2, d: 3]>; | ||
|
|
||
| type SubTup2TrailingVariadicWithLeadingOptionalElement<T extends unknown[]> = T extends [ | ||
| ...any, | ||
| ...infer B extends [0?, 1], | ||
| ~ | ||
| !!! error TS1257: A required element cannot follow an optional element. | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2TrailingVariadicWithLeadingOptionalElementTest = SubTup2TrailingVariadicWithLeadingOptionalElement<[b: 1]>; | ||
| type SubTup2TrailingVariadicWithLeadingOptionalElementTest2 = SubTup2TrailingVariadicWithLeadingOptionalElement<[a: 0, b: 1]>; | ||
| type SubTup2TrailingVariadicWithLeadingOptionalElementTest3 = SubTup2TrailingVariadicWithLeadingOptionalElement<[a: 2, b: 0, c: 1]>; | ||
| type SubTup2TrailingVariadicWithLeadingOptionalElementTest4 = SubTup2TrailingVariadicWithLeadingOptionalElement<[...a: 0[], b: 1]>; | ||
| type SubTup2TrailingVariadicWithLeadingOptionalElementTest5 = SubTup2TrailingVariadicWithLeadingOptionalElement<[...a: 1[]]>; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingOptionalElement<T extends unknown[]> = T extends [ | ||
| ...any, | ||
| ...infer B extends [0, 1?], | ||
| ] | ||
| ? B | ||
| : never; | ||
|
|
||
| type SubTup2TrailingVariadicWithTrailingOptionalElementTest = SubTup2TrailingVariadicWithTrailingOptionalElement<[a: 0]>; | ||
| type SubTup2TrailingVariadicWithTrailingOptionalElementTest2 = SubTup2TrailingVariadicWithTrailingOptionalElement<[a: 0, b: 1]>; | ||
| type SubTup2TrailingVariadicWithTrailingOptionalElementTest3 = SubTup2TrailingVariadicWithTrailingOptionalElement<[a: 2, b: 0, c: 1]>; | ||
| type SubTup2TrailingVariadicWithTrailingOptionalElementTest4 = SubTup2TrailingVariadicWithTrailingOptionalElement<[...a: 0[]]>; | ||
| type SubTup2TrailingVariadicWithTrailingOptionalElementTest5 = SubTup2TrailingVariadicWithTrailingOptionalElement<[...a: 0[], b: 1]>; | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixedLengthstill includes optional elements. In those cases, the checker could assume it needed more fixed source elements even when fewer were guaranteed, and that led to invalid slice math and crashing