-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30179 from Microsoft/fixGetParameterNameAtPosition2
Fix out-of-bounds issue in getParameterNameAtPosition
- Loading branch information
Showing
6 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/getParameterNameAtPosition.errors.txt
This file contains 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,20 @@ | ||
tests/cases/compiler/getParameterNameAtPosition.ts(9,7): error TS2345: Argument of type 'Mock<[any]>' is not assignable to parameter of type 'Tester'. | ||
Types of parameters 'args_1' and 'done' are incompatible. | ||
Type '(...args: any[]) => any' is not assignable to type 'undefined'. | ||
|
||
|
||
==== tests/cases/compiler/getParameterNameAtPosition.ts (1 errors) ==== | ||
// Repro from #30171 | ||
|
||
interface Mock<Y extends any[]> extends Function { | ||
(...args: Y): any; | ||
} | ||
type Tester = (opts: any, done: (...args: any[]) => any) => any; | ||
declare function cases(tester: Tester): void; | ||
declare function fn<Y extends any[]>(implementation?: (...args: Y) => any): Mock<Y>; | ||
cases(fn(opts => { })); | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2345: Argument of type 'Mock<[any]>' is not assignable to parameter of type 'Tester'. | ||
!!! error TS2345: Types of parameters 'args_1' and 'done' are incompatible. | ||
!!! error TS2345: Type '(...args: any[]) => any' is not assignable to type 'undefined'. | ||
|
This file contains 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,16 @@ | ||
//// [getParameterNameAtPosition.ts] | ||
// Repro from #30171 | ||
|
||
interface Mock<Y extends any[]> extends Function { | ||
(...args: Y): any; | ||
} | ||
type Tester = (opts: any, done: (...args: any[]) => any) => any; | ||
declare function cases(tester: Tester): void; | ||
declare function fn<Y extends any[]>(implementation?: (...args: Y) => any): Mock<Y>; | ||
cases(fn(opts => { })); | ||
|
||
|
||
//// [getParameterNameAtPosition.js] | ||
"use strict"; | ||
// Repro from #30171 | ||
cases(fn(function (opts) { })); |
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/getParameterNameAtPosition.symbols
This file contains 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,37 @@ | ||
=== tests/cases/compiler/getParameterNameAtPosition.ts === | ||
// Repro from #30171 | ||
|
||
interface Mock<Y extends any[]> extends Function { | ||
>Mock : Symbol(Mock, Decl(getParameterNameAtPosition.ts, 0, 0)) | ||
>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 2, 15)) | ||
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
|
||
(...args: Y): any; | ||
>args : Symbol(args, Decl(getParameterNameAtPosition.ts, 3, 5)) | ||
>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 2, 15)) | ||
} | ||
type Tester = (opts: any, done: (...args: any[]) => any) => any; | ||
>Tester : Symbol(Tester, Decl(getParameterNameAtPosition.ts, 4, 1)) | ||
>opts : Symbol(opts, Decl(getParameterNameAtPosition.ts, 5, 15)) | ||
>done : Symbol(done, Decl(getParameterNameAtPosition.ts, 5, 25)) | ||
>args : Symbol(args, Decl(getParameterNameAtPosition.ts, 5, 33)) | ||
|
||
declare function cases(tester: Tester): void; | ||
>cases : Symbol(cases, Decl(getParameterNameAtPosition.ts, 5, 64)) | ||
>tester : Symbol(tester, Decl(getParameterNameAtPosition.ts, 6, 23)) | ||
>Tester : Symbol(Tester, Decl(getParameterNameAtPosition.ts, 4, 1)) | ||
|
||
declare function fn<Y extends any[]>(implementation?: (...args: Y) => any): Mock<Y>; | ||
>fn : Symbol(fn, Decl(getParameterNameAtPosition.ts, 6, 45)) | ||
>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 7, 20)) | ||
>implementation : Symbol(implementation, Decl(getParameterNameAtPosition.ts, 7, 37)) | ||
>args : Symbol(args, Decl(getParameterNameAtPosition.ts, 7, 55)) | ||
>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 7, 20)) | ||
>Mock : Symbol(Mock, Decl(getParameterNameAtPosition.ts, 0, 0)) | ||
>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 7, 20)) | ||
|
||
cases(fn(opts => { })); | ||
>cases : Symbol(cases, Decl(getParameterNameAtPosition.ts, 5, 64)) | ||
>fn : Symbol(fn, Decl(getParameterNameAtPosition.ts, 6, 45)) | ||
>opts : Symbol(opts, Decl(getParameterNameAtPosition.ts, 8, 9)) | ||
|
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/getParameterNameAtPosition.types
This file contains 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,30 @@ | ||
=== tests/cases/compiler/getParameterNameAtPosition.ts === | ||
// Repro from #30171 | ||
|
||
interface Mock<Y extends any[]> extends Function { | ||
(...args: Y): any; | ||
>args : Y | ||
} | ||
type Tester = (opts: any, done: (...args: any[]) => any) => any; | ||
>Tester : Tester | ||
>opts : any | ||
>done : (...args: any[]) => any | ||
>args : any[] | ||
|
||
declare function cases(tester: Tester): void; | ||
>cases : (tester: Tester) => void | ||
>tester : Tester | ||
|
||
declare function fn<Y extends any[]>(implementation?: (...args: Y) => any): Mock<Y>; | ||
>fn : <Y extends any[]>(implementation?: ((...args: Y) => any) | undefined) => Mock<Y> | ||
>implementation : ((...args: Y) => any) | undefined | ||
>args : Y | ||
|
||
cases(fn(opts => { })); | ||
>cases(fn(opts => { })) : void | ||
>cases : (tester: Tester) => void | ||
>fn(opts => { }) : Mock<[any]> | ||
>fn : <Y extends any[]>(implementation?: ((...args: Y) => any) | undefined) => Mock<Y> | ||
>opts => { } : (opts: any) => void | ||
>opts : any | ||
|
This file contains 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,11 @@ | ||
// @strict: true | ||
|
||
// Repro from #30171 | ||
|
||
interface Mock<Y extends any[]> extends Function { | ||
(...args: Y): any; | ||
} | ||
type Tester = (opts: any, done: (...args: any[]) => any) => any; | ||
declare function cases(tester: Tester): void; | ||
declare function fn<Y extends any[]>(implementation?: (...args: Y) => any): Mock<Y>; | ||
cases(fn(opts => { })); |