Skip to content

Commit 2291b91

Browse files
authored
Fixed argument iteration in isSignatureApplicable (microsoft#708)
1 parent 54ec3ea commit 2291b91

15 files changed

+68
-485
lines changed

internal/checker/checker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8797,7 +8797,8 @@ func (c *Checker) isSignatureApplicable(node *ast.Node, args []*ast.Node, signat
87978797
} else {
87988798
argCount = len(args)
87998799
}
8800-
for i, arg := range args {
8800+
for i := range argCount {
8801+
arg := args[i]
88018802
if !ast.IsOmittedExpression(arg) {
88028803
paramType := c.getTypeAtPosition(signature, i)
88038804
argType := c.checkExpressionWithContextualType(arg, paramType, nil /*inferenceContext*/, checkMode)
Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
contextualTypeTupleEnd.ts(8,1): error TS2345: Argument of type '[]' is not assignable to parameter of type '[...((arg: number) => void)[], (arg: string) => void]'.
22
Source has 0 element(s) but target requires 1.
3-
contextualTypeTupleEnd.ts(9,4): error TS7006: Parameter 'x' implicitly has an 'any' type.
4-
contextualTypeTupleEnd.ts(10,4): error TS7006: Parameter 'x' implicitly has an 'any' type.
5-
contextualTypeTupleEnd.ts(10,17): error TS7006: Parameter 'x' implicitly has an 'any' type.
6-
contextualTypeTupleEnd.ts(11,4): error TS7006: Parameter 'x' implicitly has an 'any' type.
7-
contextualTypeTupleEnd.ts(11,17): error TS7006: Parameter 'x' implicitly has an 'any' type.
8-
contextualTypeTupleEnd.ts(11,30): error TS7006: Parameter 'x' implicitly has an 'any' type.
93
contextualTypeTupleEnd.ts(13,7): error TS2322: Type '[]' is not assignable to type 'Funcs'.
104
Source has 0 element(s) but target requires 1.
11-
contextualTypeTupleEnd.ts(43,5): error TS7006: Parameter 'x' implicitly has an 'any' type.
12-
contextualTypeTupleEnd.ts(44,5): error TS7006: Parameter 'x' implicitly has an 'any' type.
13-
contextualTypeTupleEnd.ts(45,5): error TS7006: Parameter 'x' implicitly has an 'any' type.
14-
contextualTypeTupleEnd.ts(52,6): error TS7006: Parameter 'a' implicitly has an 'any' type.
15-
contextualTypeTupleEnd.ts(52,14): error TS7006: Parameter 'b' implicitly has an 'any' type.
16-
contextualTypeTupleEnd.ts(52,22): error TS7006: Parameter 'c' implicitly has an 'any' type.
5+
contextualTypeTupleEnd.ts(43,12): error TS2339: Property 'foo' does not exist on type 'number'.
6+
contextualTypeTupleEnd.ts(44,12): error TS2339: Property 'bar' does not exist on type 'number'.
177

188

19-
==== contextualTypeTupleEnd.ts (14 errors) ====
9+
==== contextualTypeTupleEnd.ts (4 errors) ====
2010
type Funcs = [...((arg: number) => void)[], (arg: string) => void];
2111

2212
declare function num(x: number): void;
@@ -29,20 +19,8 @@ contextualTypeTupleEnd.ts(52,22): error TS7006: Parameter 'c' implicitly has an
2919
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[...((arg: number) => void)[], (arg: string) => void]'.
3020
!!! error TS2345: Source has 0 element(s) but target requires 1.
3121
f1(x => str(x));
32-
~
33-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
3422
f1(x => num(x), x => str(x));
35-
~
36-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
37-
~
38-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
3923
f1(x => num(x), x => num(x), x => str(x));
40-
~
41-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
42-
~
43-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
44-
~
45-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
4624

4725
const a0: Funcs = []; // Error
4826
~~
@@ -78,25 +56,17 @@ contextualTypeTupleEnd.ts(52,22): error TS7006: Parameter 'c' implicitly has an
7856

7957
example(
8058
x => x.foo, // Error
81-
~
82-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
59+
~~~
60+
!!! error TS2339: Property 'foo' does not exist on type 'number'.
8361
x => x.bar, // Error
84-
~
85-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
62+
~~~
63+
!!! error TS2339: Property 'bar' does not exist on type 'number'.
8664
x => x.baz,
87-
~
88-
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
8965
);
9066

9167
// Repro from #52846
9268

9369
declare function test(...args: [...((arg: number) => void)[], (arg: string) => void]): void;
9470

9571
test(a => a, b => b, c => c);
96-
~
97-
!!! error TS7006: Parameter 'a' implicitly has an 'any' type.
98-
~
99-
!!! error TS7006: Parameter 'b' implicitly has an 'any' type.
100-
~
101-
!!! error TS7006: Parameter 'c' implicitly has an 'any' type.
10272

testdata/baselines/reference/submodule/conformance/contextualTypeTupleEnd.errors.txt.diff

Lines changed: 0 additions & 79 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/contextualTypeTupleEnd.types

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,44 @@ f1(); // Error
2525
f1(x => str(x));
2626
>f1(x => str(x)) : void
2727
>f1 : (...args: Funcs) => void
28-
>x => str(x) : (x: any) => void
29-
>x : any
28+
>x => str(x) : (x: string) => void
29+
>x : string
3030
>str(x) : void
3131
>str : (x: string) => void
32-
>x : any
32+
>x : string
3333

3434
f1(x => num(x), x => str(x));
3535
>f1(x => num(x), x => str(x)) : void
3636
>f1 : (...args: Funcs) => void
37-
>x => num(x) : (x: any) => void
38-
>x : any
37+
>x => num(x) : (x: number) => void
38+
>x : number
3939
>num(x) : void
4040
>num : (x: number) => void
41-
>x : any
42-
>x => str(x) : (x: any) => void
43-
>x : any
41+
>x : number
42+
>x => str(x) : (x: string) => void
43+
>x : string
4444
>str(x) : void
4545
>str : (x: string) => void
46-
>x : any
46+
>x : string
4747

4848
f1(x => num(x), x => num(x), x => str(x));
4949
>f1(x => num(x), x => num(x), x => str(x)) : void
5050
>f1 : (...args: Funcs) => void
51-
>x => num(x) : (x: any) => void
52-
>x : any
51+
>x => num(x) : (x: number) => void
52+
>x : number
5353
>num(x) : void
5454
>num : (x: number) => void
55-
>x : any
56-
>x => num(x) : (x: any) => void
57-
>x : any
55+
>x : number
56+
>x => num(x) : (x: number) => void
57+
>x : number
5858
>num(x) : void
5959
>num : (x: number) => void
60-
>x : any
61-
>x => str(x) : (x: any) => void
62-
>x : any
60+
>x : number
61+
>x => str(x) : (x: string) => void
62+
>x : string
6363
>str(x) : void
6464
>str : (x: string) => void
65-
>x : any
65+
>x : string
6666

6767
const a0: Funcs = []; // Error
6868
>a0 : Funcs
@@ -180,17 +180,17 @@ example(
180180
>example : (...args: [...((n: number) => void)[], (x: any) => void]) => void
181181

182182
x => x.foo, // Error
183-
>x => x.foo : (x: any) => any
184-
>x : any
183+
>x => x.foo : (x: number) => any
184+
>x : number
185185
>x.foo : any
186-
>x : any
186+
>x : number
187187
>foo : any
188188

189189
x => x.bar, // Error
190-
>x => x.bar : (x: any) => any
191-
>x : any
190+
>x => x.bar : (x: number) => any
191+
>x : number
192192
>x.bar : any
193-
>x : any
193+
>x : number
194194
>bar : any
195195

196196
x => x.baz,
@@ -213,13 +213,13 @@ declare function test(...args: [...((arg: number) => void)[], (arg: string) => v
213213
test(a => a, b => b, c => c);
214214
>test(a => a, b => b, c => c) : void
215215
>test : (...args: [...((arg: number) => void)[], (arg: string) => void]) => void
216-
>a => a : (a: any) => any
217-
>a : any
218-
>a : any
219-
>b => b : (b: any) => any
220-
>b : any
221-
>b : any
222-
>c => c : (c: any) => any
223-
>c : any
224-
>c : any
216+
>a => a : (a: number) => number
217+
>a : number
218+
>a : number
219+
>b => b : (b: number) => number
220+
>b : number
221+
>b : number
222+
>c => c : (c: string) => string
223+
>c : string
224+
>c : string
225225

testdata/baselines/reference/submodule/conformance/contextualTypeTupleEnd.types.diff

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)