mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-13 16:34:39 -06:00
Merge pull request #5761 from Microsoft/fixErrorElaboration
Fix crash during error elaboration
This commit is contained in:
commit
262bdb5203
@ -5228,9 +5228,12 @@ namespace ts {
|
||||
const id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id;
|
||||
const related = relation[id];
|
||||
if (related !== undefined) {
|
||||
// If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate
|
||||
// errors, we can use the cached value. Otherwise, recompute the relation
|
||||
if (!elaborateErrors || (related === RelationComparisonResult.FailedAndReported)) {
|
||||
if (elaborateErrors && related === RelationComparisonResult.Failed) {
|
||||
// We are elaborating errors and the cached result is an unreported failure. Record the result as a reported
|
||||
// failure and continue computing the relation such that errors get reported.
|
||||
relation[id] = RelationComparisonResult.FailedAndReported;
|
||||
}
|
||||
else {
|
||||
return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
|
||||
Type 'number | string[][] | string' is not assignable to type 'number | string[][]'.
|
||||
Type 'string' is not assignable to type 'number | string[][]'.
|
||||
Type 'string' is not assignable to type 'string[][]'.
|
||||
Property 'push' is missing in type 'String'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
|
||||
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(
|
||||
!!! error TS2345: Type 'number | string[][] | string' is not assignable to type 'number | string[][]'.
|
||||
!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'.
|
||||
!!! error TS2345: Type 'string' is not assignable to type 'string[][]'.
|
||||
!!! error TS2345: Property 'push' is missing in type 'String'.
|
||||
|
||||
|
||||
// If the declaration includes an initializer expression (which is permitted only
|
||||
|
||||
25
tests/baselines/reference/errorElaboration.errors.txt
Normal file
25
tests/baselines/reference/errorElaboration.errors.txt
Normal file
@ -0,0 +1,25 @@
|
||||
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>>'.
|
||||
Type 'Container<Ref<string>>' is not assignable to type 'Container<Ref<number>>'.
|
||||
Type 'Ref<string>' is not assignable to type 'Ref<number>'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/errorElaboration.ts (1 errors) ====
|
||||
// Repro for #5712
|
||||
|
||||
interface Ref<T> {
|
||||
prop: T;
|
||||
}
|
||||
interface Container<T> {
|
||||
m1: Container<Ref<T>>;
|
||||
m2: T;
|
||||
}
|
||||
declare function foo(x: () => Container<Ref<number>>): void;
|
||||
let a: () => Container<Ref<string>>;
|
||||
foo(a);
|
||||
~
|
||||
!!! error TS2345: Argument of type '() => Container<Ref<string>>' is not assignable to parameter of type '() => Container<Ref<number>>'.
|
||||
!!! error TS2345: Type 'Container<Ref<string>>' is not assignable to type 'Container<Ref<number>>'.
|
||||
!!! error TS2345: Type 'Ref<string>' is not assignable to type 'Ref<number>'.
|
||||
!!! error TS2345: Type 'string' is not assignable to type 'number'.
|
||||
|
||||
19
tests/baselines/reference/errorElaboration.js
Normal file
19
tests/baselines/reference/errorElaboration.js
Normal file
@ -0,0 +1,19 @@
|
||||
//// [errorElaboration.ts]
|
||||
// Repro for #5712
|
||||
|
||||
interface Ref<T> {
|
||||
prop: T;
|
||||
}
|
||||
interface Container<T> {
|
||||
m1: Container<Ref<T>>;
|
||||
m2: T;
|
||||
}
|
||||
declare function foo(x: () => Container<Ref<number>>): void;
|
||||
let a: () => Container<Ref<string>>;
|
||||
foo(a);
|
||||
|
||||
|
||||
//// [errorElaboration.js]
|
||||
// Repro for #5712
|
||||
var a;
|
||||
foo(a);
|
||||
@ -81,7 +81,9 @@ tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
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>'.
|
||||
Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
|
||||
Property 'done' is optional in type 'IPromise<any>' but required in type 'Promise<any>'.
|
||||
Types of property 'then' are incompatible.
|
||||
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>; }'.
|
||||
Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/promisePermutations3.ts (35 errors) ====
|
||||
@ -368,5 +370,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! 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>'.
|
||||
!!! error TS2345: Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
|
||||
!!! error TS2345: Property 'done' is optional in type 'IPromise<any>' but required in type 'Promise<any>'.
|
||||
!!! error TS2345: Types of property 'then' are incompatible.
|
||||
!!! 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>; }'.
|
||||
!!! error TS2345: Type 'IPromise<any>' is not assignable to type 'Promise<any>'.
|
||||
var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok
|
||||
12
tests/cases/compiler/errorElaboration.ts
Normal file
12
tests/cases/compiler/errorElaboration.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// Repro for #5712
|
||||
|
||||
interface Ref<T> {
|
||||
prop: T;
|
||||
}
|
||||
interface Container<T> {
|
||||
m1: Container<Ref<T>>;
|
||||
m2: T;
|
||||
}
|
||||
declare function foo(x: () => Container<Ref<number>>): void;
|
||||
let a: () => Container<Ref<string>>;
|
||||
foo(a);
|
||||
Loading…
x
Reference in New Issue
Block a user