Skip to content

Commit 7a44b9e

Browse files
committed
Make elaborateErrors persist throughout type relation checks
1 parent 8610a88 commit 7a44b9e

16 files changed

+103
-7
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3872,6 +3872,7 @@ module ts {
38723872
let expandingFlags: number;
38733873
let depth = 0;
38743874
let overflow = false;
3875+
let elaborateErrors = false;
38753876

38763877
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
38773878

@@ -3886,7 +3887,8 @@ module ts {
38863887
// where errors were being reported.
38873888
if (errorInfo.next === undefined) {
38883889
errorInfo = undefined;
3889-
isRelatedTo(source, target, errorNode !== undefined, headMessage, /* elaborateErrors */ true);
3890+
elaborateErrors = true;
3891+
isRelatedTo(source, target, errorNode !== undefined, headMessage);
38903892
}
38913893
if (containingMessageChain) {
38923894
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
@@ -3904,7 +3906,7 @@ module ts {
39043906
// Ternary.True if they are related with no assumptions,
39053907
// Ternary.Maybe if they are related with assumptions of other relationships, or
39063908
// Ternary.False if they are not related.
3907-
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, elaborateErrors = false): Ternary {
3909+
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
39083910
let result: Ternary;
39093911
// both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
39103912
if (source === target) return Ternary.True;
@@ -3971,7 +3973,7 @@ module ts {
39713973
// identity relation does not use apparent type
39723974
let sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
39733975
if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType &&
3974-
(result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors, elaborateErrors))) {
3976+
(result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors))) {
39753977
errorInfo = saveErrorInfo;
39763978
return result;
39773979
}
@@ -4068,7 +4070,7 @@ module ts {
40684070
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
40694071
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
40704072
// and issue an error. Otherwise, actually compare the structure of the two types.
4071-
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean, elaborateErrors = false): Ternary {
4073+
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary {
40724074
if (overflow) {
40734075
return Ternary.False;
40744076
}

tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts(19,59): error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
22
Type 'B' is not assignable to type 'C'.
3+
Property 'z' is missing in type 'B'.
34

45

56
==== tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts (1 errors) ====
@@ -24,4 +25,5 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParamete
2425
(new Chain(new A)).then(a => new B).then(b => new C).then(c => new B).then(b => new A);
2526
~~~~~~~~~~
2627
!!! error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
27-
!!! error TS2345: Type 'B' is not assignable to type 'C'.
28+
!!! error TS2345: Type 'B' is not assignable to type 'C'.
29+
!!! error TS2345: Property 'z' is missing in type 'B'.

tests/baselines/reference/contextualTypingOfGenericFunctionTypedArguments1.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(16,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.
22
Type 'string' is not assignable to type 'Date'.
3+
Property 'toDateString' is missing in type 'String'.
34
tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(17,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.
45
Type 'string' is not assignable to type 'Date'.
56

@@ -24,6 +25,7 @@ tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(17,32):
2425
~
2526
!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.
2627
!!! error TS2345: Type 'string' is not assignable to type 'Date'.
28+
!!! error TS2345: Property 'toDateString' is missing in type 'String'.
2729
var r6 = _.forEach<number>(c2, (x) => { return x.toFixed() });
2830
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2931
!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.

tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen
55
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(25,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
66
Types of parameters 'a' and 'x' are incompatible.
77
Type 'T' is not assignable to type 'Date'.
8+
Property 'toDateString' is missing in type 'RegExp'.
89
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(37,36): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'.
910
Type 'F' is not assignable to type 'E'.
1011
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(50,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
@@ -53,6 +54,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen
5354
!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
5455
!!! error TS2345: Types of parameters 'a' and 'x' are incompatible.
5556
!!! error TS2345: Type 'T' is not assignable to type 'Date'.
57+
!!! error TS2345: Property 'toDateString' is missing in type 'RegExp'.
5658
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
5759
}
5860

tests/baselines/reference/genericCombinators2.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/compiler/genericCombinators2.ts(15,43): error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.
22
Type 'string' is not assignable to type 'Date'.
3+
Property 'toDateString' is missing in type 'String'.
34
tests/cases/compiler/genericCombinators2.ts(16,43): error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.
45
Type 'string' is not assignable to type 'Date'.
56

@@ -23,6 +24,7 @@ tests/cases/compiler/genericCombinators2.ts(16,43): error TS2345: Argument of ty
2324
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2425
!!! error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.
2526
!!! error TS2345: Type 'string' is not assignable to type 'Date'.
27+
!!! error TS2345: Property 'toDateString' is missing in type 'String'.
2628
var r5b = _.map<number, string, Date>(c2, rf1);
2729
~~~
2830
!!! error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.

tests/baselines/reference/incompatibleTypes.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tests/cases/compiler/incompatibleTypes.ts(33,7): error TS2420: Class 'C4' incorr
1717
tests/cases/compiler/incompatibleTypes.ts(42,5): error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'.
1818
Types of property 'p1' are incompatible.
1919
Type '() => string' is not assignable to type '(s: string) => number'.
20+
Type 'string' is not assignable to type 'number'.
2021
tests/cases/compiler/incompatibleTypes.ts(49,5): error TS2345: Argument of type '{ e: number; f: number; }' is not assignable to parameter of type '{ c: { b: string; }; d: string; }'.
2122
Property 'c' is missing in type '{ e: number; f: number; }'.
2223
tests/cases/compiler/incompatibleTypes.ts(66,5): error TS2322: Type '{ e: number; f: number; }' is not assignable to type '{ a: { a: string; }; b: string; }'.
@@ -92,6 +93,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) =>
9293
!!! error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'.
9394
!!! error TS2345: Types of property 'p1' are incompatible.
9495
!!! error TS2345: Type '() => string' is not assignable to type '(s: string) => number'.
96+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
9597

9698

9799
function of1(n: { a: { a: string; }; b: string; }): number;

tests/baselines/reference/interfaceAssignmentCompat.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
tests/cases/compiler/interfaceAssignmentCompat.ts(32,18): error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'.
22
Types of parameters 'a' and 'a' are incompatible.
33
Type 'IFrenchEye' is not assignable to type 'IEye'.
4+
Property 'color' is missing in type 'IFrenchEye'.
45
tests/cases/compiler/interfaceAssignmentCompat.ts(37,29): error TS2339: Property '_map' does not exist on type 'typeof Color'.
56
tests/cases/compiler/interfaceAssignmentCompat.ts(42,13): error TS2322: Type 'IEye' is not assignable to type 'IFrenchEye'.
67
Property 'coleur' is missing in type 'IEye'.
@@ -45,6 +46,7 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2322: Type 'IEy
4546
!!! error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'.
4647
!!! error TS2345: Types of parameters 'a' and 'a' are incompatible.
4748
!!! error TS2345: Type 'IFrenchEye' is not assignable to type 'IEye'.
49+
!!! error TS2345: Property 'color' is missing in type 'IFrenchEye'.
4850
// type of z inferred from specialized array type
4951
var z=x.sort(CompareEyes); // ok
5052

tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,38):
66
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(18,27): error TS2345: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
77
Types of parameters 'x' and 'x' are incompatible.
88
Type 'D' is not assignable to type 'B'.
9+
Property 'x' is missing in type 'D'.
910
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,12): error TS2344: Type 'D' does not satisfy the constraint 'A'.
1011

1112

@@ -49,4 +50,5 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,12):
4950
!!! error TS2345: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
5051
!!! error TS2345: Types of parameters 'x' and 'x' are incompatible.
5152
!!! error TS2345: Type 'D' is not assignable to type 'B'.
53+
!!! error TS2345: Property 'x' is missing in type 'D'.
5254

tests/baselines/reference/overloadsWithProvisionalErrors.errors.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
tests/cases/compiler/overloadsWithProvisionalErrors.ts(6,6): error TS2345: Argument of type '(s: string) => {}' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'.
22
Type '{}' is not assignable to type '{ a: number; b: number; }'.
3+
Property 'a' is missing in type '{}'.
34
tests/cases/compiler/overloadsWithProvisionalErrors.ts(7,17): error TS2304: Cannot find name 'blah'.
45
tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,6): error TS2345: Argument of type '(s: string) => { a: any; }' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'.
56
Type '{ a: any; }' is not assignable to type '{ a: number; b: number; }'.
7+
Property 'b' is missing in type '{ a: any; }'.
68
tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cannot find name 'blah'.
79

810

@@ -16,12 +18,14 @@ tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cann
1618
~~~~~~~~~
1719
!!! error TS2345: Argument of type '(s: string) => {}' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'.
1820
!!! error TS2345: Type '{}' is not assignable to type '{ a: number; b: number; }'.
21+
!!! error TS2345: Property 'a' is missing in type '{}'.
1922
func(s => ({ a: blah, b: 3 })); // Only error inside the function, but not outside (since it would be applicable if not for the provisional error)
2023
~~~~
2124
!!! error TS2304: Cannot find name 'blah'.
2225
func(s => ({ a: blah })); // Two errors here, one for blah not being defined, and one for the overload since it would not be applicable anyway
2326
~~~~~~~~~~~~~~~~~~
2427
!!! error TS2345: Argument of type '(s: string) => { a: any; }' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'.
2528
!!! error TS2345: Type '{ a: any; }' is not assignable to type '{ a: number; b: number; }'.
29+
!!! error TS2345: Property 'b' is missing in type '{ a: any; }'.
2630
~~~~
2731
!!! error TS2304: Cannot find name 'blah'.

tests/baselines/reference/promiseChaining1.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/compiler/promiseChaining1.ts(7,50): error TS2345: Argument of type '(x: S) => string' is not assignable to parameter of type '(x: S) => Function'.
22
Type 'string' is not assignable to type 'Function'.
3+
Property 'apply' is missing in type 'String'.
34

45

56
==== tests/cases/compiler/promiseChaining1.ts (1 errors) ====
@@ -13,6 +14,7 @@ tests/cases/compiler/promiseChaining1.ts(7,50): error TS2345: Argument of type '
1314
~~~~~~~~~~
1415
!!! error TS2345: Argument of type '(x: S) => string' is not assignable to parameter of type '(x: S) => Function'.
1516
!!! error TS2345: Type 'string' is not assignable to type 'Function'.
17+
!!! error TS2345: Property 'apply' is missing in type 'String'.
1618
return new Chain2(result);
1719
}
1820
}

0 commit comments

Comments
 (0)