Skip to content

Commit 33cee0c

Browse files
committed
Merge pull request #1017 from Microsoft/fixTypeRelationCaching
Fix type relation caching
2 parents f49af52 + bf3a629 commit 33cee0c

34 files changed

+566
-356
lines changed

src/compiler/checker.ts

+267-203
Large diffs are not rendered by default.

src/compiler/core.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
/// <reference path="types.ts"/>
22

33
module ts {
4+
5+
// Ternary values are defined such that
6+
// x & y is False if either x or y is False.
7+
// x & y is Maybe if either x or y is Maybe, but neither x or y is False.
8+
// x & y is True if both x and y are True.
9+
// x | y is False if both x and y are False.
10+
// x | y is Maybe if either x or y is Maybe, but neither x or y is True.
11+
// x | y is True if either x or y is True.
12+
export enum Ternary {
13+
False = 0,
14+
Maybe = 1,
15+
True = -1
16+
}
17+
418
export interface Map<T> {
519
[index: string]: T;
620
}

tests/baselines/reference/arrayAssignmentTest1.errors.txt

-6
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ tests/cases/compiler/arrayAssignmentTest1.ts(70,1): error TS2323: Type 'C3[]' is
2626
Property 'C2M1' is missing in type 'C3'.
2727
tests/cases/compiler/arrayAssignmentTest1.ts(75,1): error TS2323: Type 'C2[]' is not assignable to type 'C3[]'.
2828
Type 'C2' is not assignable to type 'C3'.
29-
Property 'CM3M1' is missing in type 'C2'.
3029
tests/cases/compiler/arrayAssignmentTest1.ts(76,1): error TS2323: Type 'C1[]' is not assignable to type 'C3[]'.
3130
Type 'C1' is not assignable to type 'C3'.
32-
Property 'CM3M1' is missing in type 'C1'.
3331
tests/cases/compiler/arrayAssignmentTest1.ts(77,1): error TS2323: Type 'I1[]' is not assignable to type 'C3[]'.
3432
Type 'I1' is not assignable to type 'C3'.
35-
Property 'CM3M1' is missing in type 'I1'.
3633
tests/cases/compiler/arrayAssignmentTest1.ts(79,1): error TS2323: Type '() => C1' is not assignable to type 'any[]'.
3734
Property 'push' is missing in type '() => C1'.
3835
tests/cases/compiler/arrayAssignmentTest1.ts(80,1): error TS2323: Type '{ one: number; }' is not assignable to type 'any[]'.
@@ -162,17 +159,14 @@ tests/cases/compiler/arrayAssignmentTest1.ts(85,1): error TS2323: Type 'I1' is n
162159
~~~~~~
163160
!!! error TS2323: Type 'C2[]' is not assignable to type 'C3[]'.
164161
!!! error TS2323: Type 'C2' is not assignable to type 'C3'.
165-
!!! error TS2323: Property 'CM3M1' is missing in type 'C2'.
166162
arr_c3 = arr_c1_2; // should be an error - is
167163
~~~~~~
168164
!!! error TS2323: Type 'C1[]' is not assignable to type 'C3[]'.
169165
!!! error TS2323: Type 'C1' is not assignable to type 'C3'.
170-
!!! error TS2323: Property 'CM3M1' is missing in type 'C1'.
171166
arr_c3 = arr_i1_2; // should be an error - is
172167
~~~~~~
173168
!!! error TS2323: Type 'I1[]' is not assignable to type 'C3[]'.
174169
!!! error TS2323: Type 'I1' is not assignable to type 'C3'.
175-
!!! error TS2323: Property 'CM3M1' is missing in type 'I1'.
176170

177171
arr_any = f1; // should be an error - is
178172
~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
22
Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
3-
Property 'id' is missing in type '{ foo: string; }'.
43

54

65
==== tests/cases/compiler/arrayCast.ts (1 errors) ====
@@ -10,7 +9,6 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: strin
109
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1110
!!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
1211
!!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
13-
!!! error TS2352: Property 'id' is missing in type '{ foo: string; }'.
1412

1513
// Should succeed, as the {} element causes the type of the array to be {}[]
1614
<{ id: number; }[]>[{ foo: "s" }, {}];

tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt

-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
88
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(53,9): error TS2323: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
99
Types of parameters 'y' and 'y' are incompatible.
1010
Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
11-
Types of parameters 'arg2' and 'arg2' are incompatible.
12-
Type 'Base' is not assignable to type '{ foo: number; }'.
13-
Types of property 'foo' are incompatible.
14-
Type 'string' is not assignable to type 'number'.
1511

1612

1713
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (2 errors) ====
@@ -80,10 +76,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
8076
!!! error TS2323: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
8177
!!! error TS2323: Types of parameters 'y' and 'y' are incompatible.
8278
!!! error TS2323: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
83-
!!! error TS2323: Types of parameters 'arg2' and 'arg2' are incompatible.
84-
!!! error TS2323: Type 'Base' is not assignable to type '{ foo: number; }'.
85-
!!! error TS2323: Types of property 'foo' are incompatible.
86-
!!! error TS2323: Type 'string' is not assignable to type 'number'.
8779

8880

8981
var b10: <T extends Derived>(...x: T[]) => T;

tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt

-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
88
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(53,9): error TS2323: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
99
Types of parameters 'y' and 'y' are incompatible.
1010
Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
11-
Types of parameters 'arg2' and 'arg2' are incompatible.
12-
Type 'Base' is not assignable to type '{ foo: number; }'.
13-
Types of property 'foo' are incompatible.
14-
Type 'string' is not assignable to type 'number'.
1511
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(77,9): error TS2323: Type 'new <T>(x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }'.
1612
Types of parameters 'x' and 'x' are incompatible.
1713
Type '(a: any) => any' is not assignable to type '{ new (a: number): number; new (a?: number): number; }'.
@@ -92,10 +88,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
9288
!!! error TS2323: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
9389
!!! error TS2323: Types of parameters 'y' and 'y' are incompatible.
9490
!!! error TS2323: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
95-
!!! error TS2323: Types of parameters 'arg2' and 'arg2' are incompatible.
96-
!!! error TS2323: Type 'Base' is not assignable to type '{ foo: number; }'.
97-
!!! error TS2323: Types of property 'foo' are incompatible.
98-
!!! error TS2323: Type 'string' is not assignable to type 'number'.
9991

10092

10193
var b10: new <T extends Derived>(...x: T[]) => T;

tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
1212
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(33,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
1313
Index signatures are incompatible.
1414
Type 'T' is not assignable to type 'Derived'.
15-
Property 'bar' is missing in type 'Base'.
1615
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(36,9): error TS2323: Type '{ [x: number]: Derived2; }' is not assignable to type 'A<T>'.
1716
Index signatures are incompatible.
1817
Type 'Derived2' is not assignable to type 'T'.
1918
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(37,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
2019
Index signatures are incompatible.
2120
Type 'T' is not assignable to type 'Derived2'.
22-
Property 'baz' is missing in type 'Base'.
2321

2422

2523
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts (6 errors) ====
@@ -74,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
7472
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
7573
!!! error TS2323: Index signatures are incompatible.
7674
!!! error TS2323: Type 'T' is not assignable to type 'Derived'.
77-
!!! error TS2323: Property 'bar' is missing in type 'Base'.
7875

7976
var b2: { [x: number]: Derived2; }
8077
a = b2; // error
@@ -87,7 +84,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
8784
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
8885
!!! error TS2323: Index signatures are incompatible.
8986
!!! error TS2323: Type 'T' is not assignable to type 'Derived2'.
90-
!!! error TS2323: Property 'baz' is missing in type 'Base'.
9187

9288
var b3: { [x: number]: T; }
9389
a = b3; // ok

tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
1212
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(33,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
1313
Index signatures are incompatible.
1414
Type 'T' is not assignable to type 'Derived'.
15-
Property 'bar' is missing in type 'Base'.
1615
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(36,9): error TS2323: Type '{ [x: number]: Derived2; }' is not assignable to type 'A<T>'.
1716
Index signatures are incompatible.
1817
Type 'Derived2' is not assignable to type 'T'.
1918
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(37,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
2019
Index signatures are incompatible.
2120
Type 'T' is not assignable to type 'Derived2'.
22-
Property 'baz' is missing in type 'Base'.
2321

2422

2523
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts (6 errors) ====
@@ -74,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
7472
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
7573
!!! error TS2323: Index signatures are incompatible.
7674
!!! error TS2323: Type 'T' is not assignable to type 'Derived'.
77-
!!! error TS2323: Property 'bar' is missing in type 'Base'.
7875

7976
var b2: { [x: number]: Derived2; }
8077
a = b2; // error
@@ -87,7 +84,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
8784
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
8885
!!! error TS2323: Index signatures are incompatible.
8986
!!! error TS2323: Type 'T' is not assignable to type 'Derived2'.
90-
!!! error TS2323: Property 'baz' is missing in type 'Base'.
9187

9288
var b3: { [x: number]: T; }
9389
a = b3; // ok

0 commit comments

Comments
 (0)