Skip to content

Commit d0ca71f

Browse files
committed
Correctly copy assumptions back into the relational cache
1 parent b7824e8 commit d0ca71f

3 files changed

Lines changed: 53 additions & 139 deletions

File tree

src/compiler/checker.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,7 +3471,7 @@ module ts {
34713471
// where errors were being reported.
34723472
if (errorInfo.next === undefined) {
34733473
errorInfo = undefined;
3474-
isRelatedTo(source, target, errorNode !== undefined, headMessage, true);
3474+
isRelatedTo(source, target, errorNode !== undefined, headMessage, /* mustRecompute */ true);
34753475
}
34763476
if (containingMessageChain) {
34773477
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
@@ -3652,8 +3652,11 @@ module ts {
36523652
}
36533653
var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
36543654
var related = relation[id];
3655+
//var related: RelationComparisonResult = undefined; // relation[id];
36553656
if (related !== undefined) {
3656-
if (!elaborateErrors || related === RelationComparisonResult.FailedAndReported) {
3657+
// If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate
3658+
// errors, we can use the cached value. Otherwise, recompute the relation
3659+
if (!elaborateErrors || (related === RelationComparisonResult.FailedAndReported)) {
36573660
return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
36583661
}
36593662
}
@@ -3706,9 +3709,14 @@ module ts {
37063709
if (result) {
37073710
var maybeCache = maybeStack[depth];
37083711
// If result is definitely true, copy assumptions to global cache, else copy to next level up
3709-
var destinationCache = result === Ternary.True || depth === 0 ? relation : maybeStack[depth - 1];
3710-
for (var key in maybeCache) {
3711-
destinationCache[key] = maybeCache[key] ? RelationComparisonResult.Succeeded : RelationComparisonResult.Failed;
3712+
if (result === Ternary.True || depth === 0) {
3713+
var key: string;
3714+
for (key in maybeCache) {
3715+
relation[key] = maybeCache[key] ? RelationComparisonResult.Succeeded : (reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed);
3716+
}
3717+
}
3718+
else {
3719+
copyMap(maybeCache, maybeStack[depth - 1]);
37123720
}
37133721
}
37143722
else {

tests/baselines/reference/promisePermutations.errors.txt

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
tests/cases/compiler/promisePermutations.ts(55,34): error TS2345: Argument of type '() => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
2-
Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
3-
tests/cases/compiler/promisePermutations.ts(56,34): error TS2345: Argument of type '() => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
4-
Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
5-
tests/cases/compiler/promisePermutations.ts(73,35): error TS2345: Argument of type '(x: number) => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
6-
Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
7-
tests/cases/compiler/promisePermutations.ts(74,35): error TS2345: Argument of type '(x: number) => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
8-
Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
1+
tests/cases/compiler/promisePermutations.ts(74,70): error TS2345: Argument of type '(x: number) => IPromise<number>' is not assignable to parameter of type '(value: IPromise<number>) => IPromise<number>'.
2+
Types of parameters 'x' and 'value' are incompatible.
3+
Type 'number' is not assignable to type 'IPromise<number>'.
94
tests/cases/compiler/promisePermutations.ts(79,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise<string>' is not assignable to parameter of type '(value: string) => IPromise<string>'.
105
Types of parameters 'x' and 'value' are incompatible.
116
Type 'number' is not assignable to type 'string'.
@@ -55,14 +50,10 @@ tests/cases/compiler/promisePermutations.ts(137,11): error TS2453: The type argu
5550
tests/cases/compiler/promisePermutations.ts(144,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
5651
Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
5752
Type 'string' is not assignable to type 'number'.
58-
tests/cases/compiler/promisePermutations.ts(151,21): error TS2345: Argument of type '(x: any) => IPromise<number>' is not assignable to parameter of type '(value: {}) => Promise<number>'.
59-
Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
6053
tests/cases/compiler/promisePermutations.ts(152,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
6154
Type argument candidate 'Promise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
6255
Types of property 'then' are incompatible.
6356
Type '{ <U>(success?: (value: string) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U>(success?: (value: string) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; <U>(success?: (value: string) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U>(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; }' is not assignable to type '{ <U>(success?: (value: number) => Promise<U>, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: number) => Promise<U>, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: number) => U, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; }'.
64-
tests/cases/compiler/promisePermutations.ts(153,36): error TS2345: Argument of type '(x: any) => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
65-
Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
6657
tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise<number>; (x: string): IPromise<string>; }' is not assignable to parameter of type '(value: number) => IPromise<string>'.
6758
Type 'IPromise<number>' is not assignable to type 'IPromise<string>'.
6859
Type 'number' is not assignable to type 'string'.
@@ -76,7 +67,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
7667
Type 'Promise<number>' is not assignable to type 'IPromise<string>'.
7768

7869

79-
==== tests/cases/compiler/promisePermutations.ts (38 errors) ====
70+
==== tests/cases/compiler/promisePermutations.ts (33 errors) ====
8071
interface Promise<T> {
8172
then<U>(success?: (value: T) => Promise<U>, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>;
8273
then<U>(success?: (value: T) => Promise<U>, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>;
@@ -132,13 +123,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
132123
var s1a = s1.then(testFunction, testFunction, testFunction);
133124
var s1b = s1.then(testFunctionP, testFunctionP, testFunctionP);
134125
var s1c = s1.then(testFunctionP, testFunction, testFunction);
135-
~~~~~~~~~~~~
136-
!!! error TS2345: Argument of type '() => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
137-
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
138126
var s1d = s1.then(testFunctionP, testFunction, testFunction).then(testFunction, testFunction, testFunction);
139-
~~~~~~~~~~~~
140-
!!! error TS2345: Argument of type '() => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
141-
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
142127

143128
var r2: IPromise<{ x: number; }>;
144129
var r2a = r2.then(testFunction2, testFunction2, testFunction2);
@@ -156,13 +141,11 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
156141
var s3a = s3.then(testFunction3, testFunction3, testFunction3);
157142
var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P);
158143
var s3c = s3.then(testFunction3P, testFunction3, testFunction3);
159-
~~~~~~~~~~~~~
160-
!!! error TS2345: Argument of type '(x: number) => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
161-
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
162144
var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error
163-
~~~~~~~~~~~~~
164-
!!! error TS2345: Argument of type '(x: number) => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
165-
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
145+
~~~~~~~~~~~~~
146+
!!! error TS2345: Argument of type '(x: number) => IPromise<number>' is not assignable to parameter of type '(value: IPromise<number>) => IPromise<number>'.
147+
!!! error TS2345: Types of parameters 'x' and 'value' are incompatible.
148+
!!! error TS2345: Type 'number' is not assignable to type 'IPromise<number>'.
166149

167150
var r4: IPromise<string>;
168151
var sIPromise: (x: any) => IPromise<string>;
@@ -316,19 +299,13 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
316299
var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok
317300
var s10d = s10.then(sPromise, sPromise, sPromise); // ok
318301
var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok
319-
~~~~~~~~~
320-
!!! error TS2345: Argument of type '(x: any) => IPromise<number>' is not assignable to parameter of type '(value: {}) => Promise<number>'.
321-
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
322302
var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error
323303
~~~~~~~~
324304
!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
325305
!!! error TS2453: Type argument candidate 'Promise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
326306
!!! error TS2453: Types of property 'then' are incompatible.
327307
!!! error TS2453: Type '{ <U>(success?: (value: string) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U>(success?: (value: string) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; <U>(success?: (value: string) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U>(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; }' is not assignable to type '{ <U>(success?: (value: number) => Promise<U>, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: number) => Promise<U>, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: number) => U, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; }'.
328308
var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok
329-
~~~~~~~~~
330-
!!! error TS2345: Argument of type '(x: any) => IPromise<number>' is not assignable to parameter of type '(error: any) => Promise<number>'.
331-
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'Promise<number>'.
332309

333310
var r11: IPromise<number>;
334311
var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error

0 commit comments

Comments
 (0)