-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixed array expression spreads into variadic const calls #52845
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
Merged
jakebailey
merged 2 commits into
microsoft:main
from
Andarist:fix/array-spread-into-const-call
Mar 8, 2023
Merged
Changes from all commits
Commits
Show all changes
2 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
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,29 @@ | ||
tests/cases/conformance/es6/spread/arraySpreadInCall.ts(21,12): error TS2554: Expected 0-1 arguments, but got 2. | ||
|
||
|
||
==== tests/cases/conformance/es6/spread/arraySpreadInCall.ts (1 errors) ==== | ||
declare function f1(a: number, b: number, c: number, d: number, e: number, f: number): void; | ||
f1(1, 2, 3, 4, ...[5, 6]); | ||
f1(...[1], 2, 3, 4, 5, 6); | ||
f1(1, 2, ...[3, 4], 5, 6); | ||
f1(1, 2, ...[3], 4, ...[5, 6]); | ||
f1(...[1, 2], ...[3, 4], ...[5, 6]); | ||
|
||
declare function f2<T extends unknown[]>(...args: T): T; | ||
const x21 = f2(...[1, 'foo']) | ||
const x22 = f2(true, ...[1, 'foo']) | ||
|
||
declare function f3<T extends readonly unknown[]>(...args: T): T; | ||
const x31 = f3(...[1, 'foo']) | ||
const x32 = f3(true, ...[1, 'foo']) | ||
|
||
// dicovered in #52845#issuecomment-1459132562 | ||
interface IAction { | ||
run(event?: unknown): unknown; | ||
} | ||
declare const action: IAction | ||
action.run(...[100, 'foo']) // error | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2554: Expected 0-1 arguments, but got 2. | ||
|
||
|
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,73 @@ | ||
=== tests/cases/conformance/es6/spread/arraySpreadInCall.ts === | ||
declare function f1(a: number, b: number, c: number, d: number, e: number, f: number): void; | ||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0)) | ||
>a : Symbol(a, Decl(arraySpreadInCall.ts, 0, 20)) | ||
>b : Symbol(b, Decl(arraySpreadInCall.ts, 0, 30)) | ||
>c : Symbol(c, Decl(arraySpreadInCall.ts, 0, 41)) | ||
>d : Symbol(d, Decl(arraySpreadInCall.ts, 0, 52)) | ||
>e : Symbol(e, Decl(arraySpreadInCall.ts, 0, 63)) | ||
>f : Symbol(f, Decl(arraySpreadInCall.ts, 0, 74)) | ||
|
||
f1(1, 2, 3, 4, ...[5, 6]); | ||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0)) | ||
|
||
f1(...[1], 2, 3, 4, 5, 6); | ||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0)) | ||
|
||
f1(1, 2, ...[3, 4], 5, 6); | ||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0)) | ||
|
||
f1(1, 2, ...[3], 4, ...[5, 6]); | ||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0)) | ||
|
||
f1(...[1, 2], ...[3, 4], ...[5, 6]); | ||
>f1 : Symbol(f1, Decl(arraySpreadInCall.ts, 0, 0)) | ||
|
||
declare function f2<T extends unknown[]>(...args: T): T; | ||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36)) | ||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 7, 20)) | ||
>args : Symbol(args, Decl(arraySpreadInCall.ts, 7, 41)) | ||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 7, 20)) | ||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 7, 20)) | ||
|
||
const x21 = f2(...[1, 'foo']) | ||
>x21 : Symbol(x21, Decl(arraySpreadInCall.ts, 8, 5)) | ||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36)) | ||
|
||
const x22 = f2(true, ...[1, 'foo']) | ||
>x22 : Symbol(x22, Decl(arraySpreadInCall.ts, 9, 5)) | ||
>f2 : Symbol(f2, Decl(arraySpreadInCall.ts, 5, 36)) | ||
|
||
declare function f3<T extends readonly unknown[]>(...args: T): T; | ||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35)) | ||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 11, 20)) | ||
>args : Symbol(args, Decl(arraySpreadInCall.ts, 11, 50)) | ||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 11, 20)) | ||
>T : Symbol(T, Decl(arraySpreadInCall.ts, 11, 20)) | ||
|
||
const x31 = f3(...[1, 'foo']) | ||
>x31 : Symbol(x31, Decl(arraySpreadInCall.ts, 12, 5)) | ||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35)) | ||
|
||
const x32 = f3(true, ...[1, 'foo']) | ||
>x32 : Symbol(x32, Decl(arraySpreadInCall.ts, 13, 5)) | ||
>f3 : Symbol(f3, Decl(arraySpreadInCall.ts, 9, 35)) | ||
|
||
// dicovered in #52845#issuecomment-1459132562 | ||
interface IAction { | ||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 13, 35)) | ||
|
||
run(event?: unknown): unknown; | ||
>run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 16, 19)) | ||
>event : Symbol(event, Decl(arraySpreadInCall.ts, 17, 8)) | ||
} | ||
declare const action: IAction | ||
>action : Symbol(action, Decl(arraySpreadInCall.ts, 19, 13)) | ||
>IAction : Symbol(IAction, Decl(arraySpreadInCall.ts, 13, 35)) | ||
|
||
action.run(...[100, 'foo']) // error | ||
>action.run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 16, 19)) | ||
>action : Symbol(action, Decl(arraySpreadInCall.ts, 19, 13)) | ||
>run : Symbol(IAction.run, Decl(arraySpreadInCall.ts, 16, 19)) | ||
|
||
|
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,142 @@ | ||
=== tests/cases/conformance/es6/spread/arraySpreadInCall.ts === | ||
declare function f1(a: number, b: number, c: number, d: number, e: number, f: number): void; | ||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void | ||
>a : number | ||
>b : number | ||
>c : number | ||
>d : number | ||
>e : number | ||
>f : number | ||
|
||
f1(1, 2, 3, 4, ...[5, 6]); | ||
>f1(1, 2, 3, 4, ...[5, 6]) : void | ||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void | ||
>1 : 1 | ||
>2 : 2 | ||
>3 : 3 | ||
>4 : 4 | ||
>...[5, 6] : number | ||
>[5, 6] : readonly [number, number] | ||
>5 : 5 | ||
>6 : 6 | ||
|
||
f1(...[1], 2, 3, 4, 5, 6); | ||
>f1(...[1], 2, 3, 4, 5, 6) : void | ||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void | ||
>...[1] : number | ||
>[1] : readonly [number] | ||
>1 : 1 | ||
>2 : 2 | ||
>3 : 3 | ||
>4 : 4 | ||
>5 : 5 | ||
>6 : 6 | ||
|
||
f1(1, 2, ...[3, 4], 5, 6); | ||
>f1(1, 2, ...[3, 4], 5, 6) : void | ||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void | ||
>1 : 1 | ||
>2 : 2 | ||
>...[3, 4] : number | ||
>[3, 4] : readonly [number, number] | ||
>3 : 3 | ||
>4 : 4 | ||
>5 : 5 | ||
>6 : 6 | ||
|
||
f1(1, 2, ...[3], 4, ...[5, 6]); | ||
>f1(1, 2, ...[3], 4, ...[5, 6]) : void | ||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void | ||
>1 : 1 | ||
>2 : 2 | ||
>...[3] : number | ||
>[3] : readonly [number] | ||
>3 : 3 | ||
>4 : 4 | ||
>...[5, 6] : number | ||
>[5, 6] : readonly [number, number] | ||
>5 : 5 | ||
>6 : 6 | ||
|
||
f1(...[1, 2], ...[3, 4], ...[5, 6]); | ||
>f1(...[1, 2], ...[3, 4], ...[5, 6]) : void | ||
>f1 : (a: number, b: number, c: number, d: number, e: number, f: number) => void | ||
>...[1, 2] : number | ||
>[1, 2] : readonly [number, number] | ||
>1 : 1 | ||
>2 : 2 | ||
>...[3, 4] : number | ||
>[3, 4] : readonly [number, number] | ||
>3 : 3 | ||
>4 : 4 | ||
>...[5, 6] : number | ||
>[5, 6] : readonly [number, number] | ||
>5 : 5 | ||
>6 : 6 | ||
|
||
declare function f2<T extends unknown[]>(...args: T): T; | ||
>f2 : <T extends unknown[]>(...args: T) => T | ||
>args : T | ||
|
||
const x21 = f2(...[1, 'foo']) | ||
>x21 : [number, string] | ||
>f2(...[1, 'foo']) : [number, string] | ||
>f2 : <T extends unknown[]>(...args: T) => T | ||
>...[1, 'foo'] : string | number | ||
>[1, 'foo'] : readonly [number, string] | ||
>1 : 1 | ||
>'foo' : "foo" | ||
|
||
const x22 = f2(true, ...[1, 'foo']) | ||
>x22 : [boolean, number, string] | ||
>f2(true, ...[1, 'foo']) : [boolean, number, string] | ||
>f2 : <T extends unknown[]>(...args: T) => T | ||
>true : true | ||
>...[1, 'foo'] : string | number | ||
>[1, 'foo'] : readonly [number, string] | ||
>1 : 1 | ||
>'foo' : "foo" | ||
|
||
declare function f3<T extends readonly unknown[]>(...args: T): T; | ||
>f3 : <T extends readonly unknown[]>(...args: T) => T | ||
>args : T | ||
|
||
const x31 = f3(...[1, 'foo']) | ||
>x31 : [number, string] | ||
>f3(...[1, 'foo']) : [number, string] | ||
>f3 : <T extends readonly unknown[]>(...args: T) => T | ||
>...[1, 'foo'] : string | number | ||
>[1, 'foo'] : readonly [number, string] | ||
>1 : 1 | ||
>'foo' : "foo" | ||
|
||
const x32 = f3(true, ...[1, 'foo']) | ||
>x32 : [boolean, number, string] | ||
>f3(true, ...[1, 'foo']) : [boolean, number, string] | ||
>f3 : <T extends readonly unknown[]>(...args: T) => T | ||
>true : true | ||
>...[1, 'foo'] : string | number | ||
>[1, 'foo'] : readonly [number, string] | ||
>1 : 1 | ||
>'foo' : "foo" | ||
|
||
// dicovered in #52845#issuecomment-1459132562 | ||
interface IAction { | ||
run(event?: unknown): unknown; | ||
>run : (event?: unknown) => unknown | ||
>event : unknown | ||
} | ||
declare const action: IAction | ||
>action : IAction | ||
|
||
action.run(...[100, 'foo']) // error | ||
>action.run(...[100, 'foo']) : unknown | ||
>action.run : (event?: unknown) => unknown | ||
>action : IAction | ||
>run : (event?: unknown) => unknown | ||
>...[100, 'foo'] : string | number | ||
>[100, 'foo'] : readonly [number, string] | ||
>100 : 100 | ||
>'foo' : "foo" | ||
|
||
|
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
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
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
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.
initially, I wanted to adjust
isConstContext
- but spread arguments never have contextual types + asking for a contextual type of an argument callsgetEffectiveCallArguments
and we are within this call already, so it was creating an infinite loopI was looking into other ways to check for the const context for such spread expressions but I couldn't figure out anything since I can't even check the signature (it's still
resolvingSignature
at this point).