Skip to content

Commit 262bdb5

Browse files
committed
Merge pull request #5761 from Microsoft/fixErrorElaboration
Fix crash during error elaboration
2 parents fbaba90 + c5dd297 commit 262bdb5

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5228,9 +5228,12 @@ namespace ts {
52285228
const id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id;
52295229
const related = relation[id];
52305230
if (related !== undefined) {
5231-
// If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate
5232-
// errors, we can use the cached value. Otherwise, recompute the relation
5233-
if (!elaborateErrors || (related === RelationComparisonResult.FailedAndReported)) {
5231+
if (elaborateErrors && related === RelationComparisonResult.Failed) {
5232+
// We are elaborating errors and the cached result is an unreported failure. Record the result as a reported
5233+
// failure and continue computing the relation such that errors get reported.
5234+
relation[id] = RelationComparisonResult.FailedAndReported;
5235+
}
5236+
else {
52345237
return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
52355238
}
52365239
}

tests/baselines/reference/destructuringParameterDeclaration2.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
88
Type 'number | string[][] | string' is not assignable to type 'number | string[][]'.
99
Type 'string' is not assignable to type 'number | string[][]'.
1010
Type 'string' is not assignable to type 'string[][]'.
11+
Property 'push' is missing in type 'String'.
1112
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
1213
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
1314
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(23,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'.
@@ -77,6 +78,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
7778
!!! error TS2345: Type 'number | string[][] | string' is not assignable to type 'number | string[][]'.
7879
!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'.
7980
!!! error TS2345: Type 'string' is not assignable to type 'string[][]'.
81+
!!! error TS2345: Property 'push' is missing in type 'String'.
8082

8183

8284
// If the declaration includes an initializer expression (which is permitted only
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
tests/cases/compiler/errorElaboration.ts(12,5): error TS2345: Argument of type '() => Container<Ref<string>>' is not assignable to parameter of type '() => Container<Ref<number>>'.
2+
Type 'Container<Ref<string>>' is not assignable to type 'Container<Ref<number>>'.
3+
Type 'Ref<string>' is not assignable to type 'Ref<number>'.
4+
Type 'string' is not assignable to type 'number'.
5+
6+
7+
==== tests/cases/compiler/errorElaboration.ts (1 errors) ====
8+
// Repro for #5712
9+
10+
interface Ref<T> {
11+
prop: T;
12+
}
13+
interface Container<T> {
14+
m1: Container<Ref<T>>;
15+
m2: T;
16+
}
17+
declare function foo(x: () => Container<Ref<number>>): void;
18+
let a: () => Container<Ref<string>>;
19+
foo(a);
20+
~
21+
!!! error TS2345: Argument of type '() => Container<Ref<string>>' is not assignable to parameter of type '() => Container<Ref<number>>'.
22+
!!! error TS2345: Type 'Container<Ref<string>>' is not assignable to type 'Container<Ref<number>>'.
23+
!!! error TS2345: Type 'Ref<string>' is not assignable to type 'Ref<number>'.
24+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
25+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [errorElaboration.ts]
2+
// Repro for #5712
3+
4+
interface Ref<T> {
5+
prop: T;
6+
}
7+
interface Container<T> {
8+
m1: Container<Ref<T>>;
9+
m2: T;
10+
}
11+
declare function foo(x: () => Container<Ref<number>>): void;
12+
let a: () => Container<Ref<string>>;
13+
foo(a);
14+
15+
16+
//// [errorElaboration.js]
17+
// Repro for #5712
18+
var a;
19+
foo(a);

tests/baselines/reference/promisePermutations3.errors.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of
8181
Type 'number' is not assignable to type 'string'.
8282
tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ <T>(x: T): IPromise<T>; <T>(x: T, y: T): Promise<T>; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise<any>'.
8383
Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
84-
Property 'done' is optional in type 'IPromise<any>' but required in type 'Promise<any>'.
84+
Types of property 'then' are incompatible.
85+
Type '<U>(success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise<U>' is not assignable to type '{ <U>(success?: (value: any) => Promise<U>, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: any) => Promise<U>, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: any) => U, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; }'.
86+
Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
8587

8688

8789
==== tests/cases/compiler/promisePermutations3.ts (35 errors) ====
@@ -368,5 +370,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
368370
~~~~~~~~~~~~~~~
369371
!!! error TS2345: Argument of type '{ <T>(x: T): IPromise<T>; <T>(x: T, y: T): Promise<T>; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise<any>'.
370372
!!! error TS2345: Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
371-
!!! error TS2345: Property 'done' is optional in type 'IPromise<any>' but required in type 'Promise<any>'.
373+
!!! error TS2345: Types of property 'then' are incompatible.
374+
!!! error TS2345: Type '<U>(success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise<U>' is not assignable to type '{ <U>(success?: (value: any) => Promise<U>, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: any) => Promise<U>, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: any) => U, error?: (error: any) => Promise<U>, progress?: (progress: any) => void): Promise<U>; <U>(success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise<U>; }'.
375+
!!! error TS2345: Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
372376
var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Repro for #5712
2+
3+
interface Ref<T> {
4+
prop: T;
5+
}
6+
interface Container<T> {
7+
m1: Container<Ref<T>>;
8+
m2: T;
9+
}
10+
declare function foo(x: () => Container<Ref<number>>): void;
11+
let a: () => Container<Ref<string>>;
12+
foo(a);

0 commit comments

Comments
 (0)