Skip to content

Commit e92f50b

Browse files
committed
Now that we speculate, we can and should reset argCheckMode for every overload we check
1 parent ada8221 commit e92f50b

14 files changed

+346
-118
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34964,7 +34964,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3496434964
// For a decorator, no arguments are susceptible to contextual typing due to the fact
3496534965
// decorators are applied to a declaration by the emitter, and not to an expression.
3496634966
const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
34967-
let argCheckMode = !isDecorator && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? CheckMode.SkipContextSensitive : CheckMode.Normal;
3496834967

3496934968
// The following variables are captured and modified by calls to chooseOverload.
3497034969
// If overload resolution or type argument inference fails, we want to report the
@@ -35173,12 +35172,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3517335172
return candidate;
3517435173
}
3517535174

35175+
const initialCheckMode = !isDecorator && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? CheckMode.SkipContextSensitive : CheckMode.Normal;
3517635176
for (let candidateIndex = 0; candidateIndex < candidates.length; candidateIndex++) {
3517735177
const candidate = candidates[candidateIndex];
3517835178
if (!hasCorrectTypeArgumentArity(candidate, typeArguments) || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) {
3517935179
continue;
3518035180
}
3518135181
const result = speculate(() => {
35182+
let argCheckMode = initialCheckMode;
3518235183
let checkCandidate: Signature;
3518335184
let inferenceContext: InferenceContext | undefined;
3518435185

tests/baselines/reference/contextuallyTypedStringLiteralsInJsxAttributes02.errors.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ file.tsx(28,13): error TS2769: No overload matches this call.
1010
Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
1111
Property 'extra' does not exist on type 'IntrinsicAttributes & ButtonProps'.
1212
Overload 2 of 2, '(linkProps: LinkProps): Element', gave the following error.
13-
Type '{ onClick: (k: any) => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
14-
Property 'onClick' does not exist on type 'IntrinsicAttributes & LinkProps'.
13+
Property 'goTo' is missing in type '{ onClick: {}; extra: true; }' but required in type 'LinkProps'.
1514
file.tsx(29,43): error TS2769: No overload matches this call.
1615
Overload 1 of 2, '(buttonProps: ButtonProps): Element', gave the following error.
1716
Type '{ extra: true; goTo: string; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
@@ -75,8 +74,8 @@ file.tsx(36,44): error TS2322: Type '{ extra: true; goTo: "home"; }' is not assi
7574
!!! error TS2769: Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
7675
!!! error TS2769: Property 'extra' does not exist on type 'IntrinsicAttributes & ButtonProps'.
7776
!!! error TS2769: Overload 2 of 2, '(linkProps: LinkProps): Element', gave the following error.
78-
!!! error TS2769: Type '{ onClick: (k: any) => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
79-
!!! error TS2769: Property 'onClick' does not exist on type 'IntrinsicAttributes & LinkProps'.
77+
!!! error TS2769: Property 'goTo' is missing in type '{ onClick: {}; extra: true; }' but required in type 'LinkProps'.
78+
!!! related TS2728 file.tsx:13:5: 'goTo' is declared here.
8079
const b3 = <MainButton {...{goTo:"home"}} extra />; // goTo has type"home" | "contact"
8180
~~~~~
8281
!!! error TS2769: No overload matches this call.
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
destructuringTuple.ts(11,7): error TS2461: Type 'unknown' is not an array type.
2-
destructuringTuple.ts(11,48): error TS18046: 'accu' is of type 'unknown'.
1+
destructuringTuple.ts(11,7): error TS2461: Type 'number' is not an array type.
2+
destructuringTuple.ts(11,27): error TS2769: No overload matches this call.
3+
Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
4+
Argument of type 'never[]' is not assignable to parameter of type 'number'.
5+
Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
6+
Type 'never[]' is not assignable to type '[]'.
7+
Target allows only 0 element(s) but source may have more.
8+
destructuringTuple.ts(11,53): error TS2339: Property 'concat' does not exist on type 'number'.
39

410

5-
==== destructuringTuple.ts (2 errors) ====
11+
==== destructuringTuple.ts (3 errors) ====
612
declare var tuple: [boolean, number, ...string[]];
713

814
const [a, b, c, ...rest] = tuple;
@@ -15,9 +21,17 @@ destructuringTuple.ts(11,48): error TS18046: 'accu' is of type 'unknown'.
1521

1622
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
1723
~~~~~~~
18-
!!! error TS2461: Type 'unknown' is not an array type.
19-
~~~~
20-
!!! error TS18046: 'accu' is of type 'unknown'.
24+
!!! error TS2461: Type 'number' is not an array type.
25+
~~~~~~
26+
!!! error TS2769: No overload matches this call.
27+
!!! error TS2769: Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
28+
!!! error TS2769: Argument of type 'never[]' is not assignable to parameter of type 'number'.
29+
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
30+
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
31+
!!! error TS2769: Target allows only 0 element(s) but source may have more.
32+
!!! related TS6502 lib.es5.d.ts:--:--: The expected type comes from the return type of this signature.
33+
~~~~~~
34+
!!! error TS2339: Property 'concat' does not exist on type 'number'.
2135

2236
const [oops2] = [1, 2, 3].reduce((acc: number[], e) => acc.concat(e), []);
2337

tests/baselines/reference/destructuringTuple.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ declare var receiver: typeof tuple;
2626

2727
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
2828
>oops1 : any
29-
>[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : unknown
29+
>[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : number
3030
>[1, 2, 3].reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
3131
>[1, 2, 3] : number[]
3232
>1 : 1
3333
>2 : 2
3434
>3 : 3
3535
>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
36-
>(accu, el) => accu.concat(el) : (accu: unknown, el: number) => any
37-
>accu : unknown
36+
>(accu, el) => accu.concat(el) : (accu: number, el: number) => any
37+
>accu : number
3838
>el : number
3939
>accu.concat(el) : any
4040
>accu.concat : any
41-
>accu : unknown
41+
>accu : number
4242
>concat : any
4343
>el : number
4444
>[] : never[]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [tests/cases/compiler/functionOverloadInformsPriorArgumentType.ts] ////
2+
3+
//// [functionOverloadInformsPriorArgumentType.ts]
4+
enum ModifierFlags {
5+
None = 0,
6+
In = 1,
7+
Out = 2,
8+
Const = 4,
9+
Other = 8,
10+
}
11+
12+
interface Declaration {
13+
modifierFlags: ModifierFlags;
14+
}
15+
16+
declare function getEffectiveModifierFlags(d: Declaration): ModifierFlags;
17+
18+
declare function reduceLeft<T, U>(array: readonly T[] | undefined, f: (memo: U, value: T, i: number) => U, initial: U, start?: number, count?: number): U;
19+
// only has an issue when the 2nd overload is present, even though it has an arity mismatch
20+
declare function reduceLeft<T>(array: readonly T[], f: (memo: T, value: T, i: number) => T): T | undefined;
21+
22+
function getTypeParameterModifiers(declarations: Declaration[]): ModifierFlags {
23+
return reduceLeft(declarations, (modifiers, d) => modifiers | getEffectiveModifierFlags(d), ModifierFlags.None) & (ModifierFlags.In | ModifierFlags.Out | ModifierFlags.Const);
24+
}
25+
26+
//// [functionOverloadInformsPriorArgumentType.js]
27+
"use strict";
28+
var ModifierFlags;
29+
(function (ModifierFlags) {
30+
ModifierFlags[ModifierFlags["None"] = 0] = "None";
31+
ModifierFlags[ModifierFlags["In"] = 1] = "In";
32+
ModifierFlags[ModifierFlags["Out"] = 2] = "Out";
33+
ModifierFlags[ModifierFlags["Const"] = 4] = "Const";
34+
ModifierFlags[ModifierFlags["Other"] = 8] = "Other";
35+
})(ModifierFlags || (ModifierFlags = {}));
36+
function getTypeParameterModifiers(declarations) {
37+
return reduceLeft(declarations, function (modifiers, d) { return modifiers | getEffectiveModifierFlags(d); }, ModifierFlags.None) & (ModifierFlags.In | ModifierFlags.Out | ModifierFlags.Const);
38+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//// [tests/cases/compiler/functionOverloadInformsPriorArgumentType.ts] ////
2+
3+
=== functionOverloadInformsPriorArgumentType.ts ===
4+
enum ModifierFlags {
5+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
6+
7+
None = 0,
8+
>None : Symbol(ModifierFlags.None, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 20))
9+
10+
In = 1,
11+
>In : Symbol(ModifierFlags.In, Decl(functionOverloadInformsPriorArgumentType.ts, 1, 13))
12+
13+
Out = 2,
14+
>Out : Symbol(ModifierFlags.Out, Decl(functionOverloadInformsPriorArgumentType.ts, 2, 11))
15+
16+
Const = 4,
17+
>Const : Symbol(ModifierFlags.Const, Decl(functionOverloadInformsPriorArgumentType.ts, 3, 12))
18+
19+
Other = 8,
20+
>Other : Symbol(ModifierFlags.Other, Decl(functionOverloadInformsPriorArgumentType.ts, 4, 14))
21+
}
22+
23+
interface Declaration {
24+
>Declaration : Symbol(Declaration, Decl(functionOverloadInformsPriorArgumentType.ts, 6, 1))
25+
26+
modifierFlags: ModifierFlags;
27+
>modifierFlags : Symbol(Declaration.modifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 8, 23))
28+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
29+
}
30+
31+
declare function getEffectiveModifierFlags(d: Declaration): ModifierFlags;
32+
>getEffectiveModifierFlags : Symbol(getEffectiveModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 10, 1))
33+
>d : Symbol(d, Decl(functionOverloadInformsPriorArgumentType.ts, 12, 43))
34+
>Declaration : Symbol(Declaration, Decl(functionOverloadInformsPriorArgumentType.ts, 6, 1))
35+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
36+
37+
declare function reduceLeft<T, U>(array: readonly T[] | undefined, f: (memo: U, value: T, i: number) => U, initial: U, start?: number, count?: number): U;
38+
>reduceLeft : Symbol(reduceLeft, Decl(functionOverloadInformsPriorArgumentType.ts, 12, 74), Decl(functionOverloadInformsPriorArgumentType.ts, 14, 154))
39+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 28))
40+
>U : Symbol(U, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 30))
41+
>array : Symbol(array, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 34))
42+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 28))
43+
>f : Symbol(f, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 66))
44+
>memo : Symbol(memo, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 71))
45+
>U : Symbol(U, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 30))
46+
>value : Symbol(value, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 79))
47+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 28))
48+
>i : Symbol(i, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 89))
49+
>U : Symbol(U, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 30))
50+
>initial : Symbol(initial, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 106))
51+
>U : Symbol(U, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 30))
52+
>start : Symbol(start, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 118))
53+
>count : Symbol(count, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 134))
54+
>U : Symbol(U, Decl(functionOverloadInformsPriorArgumentType.ts, 14, 30))
55+
56+
// only has an issue when the 2nd overload is present, even though it has an arity mismatch
57+
declare function reduceLeft<T>(array: readonly T[], f: (memo: T, value: T, i: number) => T): T | undefined;
58+
>reduceLeft : Symbol(reduceLeft, Decl(functionOverloadInformsPriorArgumentType.ts, 12, 74), Decl(functionOverloadInformsPriorArgumentType.ts, 14, 154))
59+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 28))
60+
>array : Symbol(array, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 31))
61+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 28))
62+
>f : Symbol(f, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 51))
63+
>memo : Symbol(memo, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 56))
64+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 28))
65+
>value : Symbol(value, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 64))
66+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 28))
67+
>i : Symbol(i, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 74))
68+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 28))
69+
>T : Symbol(T, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 28))
70+
71+
function getTypeParameterModifiers(declarations: Declaration[]): ModifierFlags {
72+
>getTypeParameterModifiers : Symbol(getTypeParameterModifiers, Decl(functionOverloadInformsPriorArgumentType.ts, 16, 107))
73+
>declarations : Symbol(declarations, Decl(functionOverloadInformsPriorArgumentType.ts, 18, 35))
74+
>Declaration : Symbol(Declaration, Decl(functionOverloadInformsPriorArgumentType.ts, 6, 1))
75+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
76+
77+
return reduceLeft(declarations, (modifiers, d) => modifiers | getEffectiveModifierFlags(d), ModifierFlags.None) & (ModifierFlags.In | ModifierFlags.Out | ModifierFlags.Const);
78+
>reduceLeft : Symbol(reduceLeft, Decl(functionOverloadInformsPriorArgumentType.ts, 12, 74), Decl(functionOverloadInformsPriorArgumentType.ts, 14, 154))
79+
>declarations : Symbol(declarations, Decl(functionOverloadInformsPriorArgumentType.ts, 18, 35))
80+
>modifiers : Symbol(modifiers, Decl(functionOverloadInformsPriorArgumentType.ts, 19, 37))
81+
>d : Symbol(d, Decl(functionOverloadInformsPriorArgumentType.ts, 19, 47))
82+
>modifiers : Symbol(modifiers, Decl(functionOverloadInformsPriorArgumentType.ts, 19, 37))
83+
>getEffectiveModifierFlags : Symbol(getEffectiveModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 10, 1))
84+
>d : Symbol(d, Decl(functionOverloadInformsPriorArgumentType.ts, 19, 47))
85+
>ModifierFlags.None : Symbol(ModifierFlags.None, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 20))
86+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
87+
>None : Symbol(ModifierFlags.None, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 20))
88+
>ModifierFlags.In : Symbol(ModifierFlags.In, Decl(functionOverloadInformsPriorArgumentType.ts, 1, 13))
89+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
90+
>In : Symbol(ModifierFlags.In, Decl(functionOverloadInformsPriorArgumentType.ts, 1, 13))
91+
>ModifierFlags.Out : Symbol(ModifierFlags.Out, Decl(functionOverloadInformsPriorArgumentType.ts, 2, 11))
92+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
93+
>Out : Symbol(ModifierFlags.Out, Decl(functionOverloadInformsPriorArgumentType.ts, 2, 11))
94+
>ModifierFlags.Const : Symbol(ModifierFlags.Const, Decl(functionOverloadInformsPriorArgumentType.ts, 3, 12))
95+
>ModifierFlags : Symbol(ModifierFlags, Decl(functionOverloadInformsPriorArgumentType.ts, 0, 0))
96+
>Const : Symbol(ModifierFlags.Const, Decl(functionOverloadInformsPriorArgumentType.ts, 3, 12))
97+
}

0 commit comments

Comments
 (0)