Skip to content

Commit bb7f617

Browse files
committed
PR feedback and another test
1 parent d8ef7b6 commit bb7f617

File tree

4 files changed

+114
-1
lines changed

4 files changed

+114
-1
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3574,7 +3574,8 @@ module ts {
35743574

35753575
// Since removeSubtypes checks the subtype relation, and the subtype relation on a union
35763576
// may attempt to reduce a union, it is possible that removeSubtypes could be called
3577-
// recursively on the same set of types.
3577+
// recursively on the same set of types. The removeSubtypesStack is used to track which
3578+
// sets of types are currently undergoing subtype reduction.
35783579
let removeSubtypesStack: string[] = [];
35793580
function removeSubtypes(types: Type[]) {
35803581
let typeListId = getTypeListId(types);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
tests/cases/compiler/unionTypeWithRecursiveSubtypeReduction2.ts(19,1): error TS2322: Type 'Property' is not assignable to type 'Class'.
2+
Types of property 'parent' are incompatible.
3+
Type 'Module | Class' is not assignable to type 'Namespace'.
4+
Type 'Class' is not assignable to type 'Namespace'.
5+
Property 'members' is missing in type 'Class'.
6+
tests/cases/compiler/unionTypeWithRecursiveSubtypeReduction2.ts(20,1): error TS2322: Type 'Class' is not assignable to type 'Property'.
7+
Types of property 'parent' are incompatible.
8+
Type 'Namespace' is not assignable to type 'Module | Class'.
9+
Type 'Namespace' is not assignable to type 'Class'.
10+
Property 'parent' is missing in type 'Namespace'.
11+
12+
13+
==== tests/cases/compiler/unionTypeWithRecursiveSubtypeReduction2.ts (2 errors) ====
14+
class Module {
15+
public members: Class[];
16+
}
17+
18+
class Namespace {
19+
public members: (Class | Property)[];
20+
}
21+
22+
class Class {
23+
public parent: Namespace;
24+
}
25+
26+
class Property {
27+
public parent: Module | Class;
28+
}
29+
30+
var c: Class;
31+
var p: Property;
32+
c = p;
33+
~
34+
!!! error TS2322: Type 'Property' is not assignable to type 'Class'.
35+
!!! error TS2322: Types of property 'parent' are incompatible.
36+
!!! error TS2322: Type 'Module | Class' is not assignable to type 'Namespace'.
37+
!!! error TS2322: Type 'Class' is not assignable to type 'Namespace'.
38+
!!! error TS2322: Property 'members' is missing in type 'Class'.
39+
p = c;
40+
~
41+
!!! error TS2322: Type 'Class' is not assignable to type 'Property'.
42+
!!! error TS2322: Types of property 'parent' are incompatible.
43+
!!! error TS2322: Type 'Namespace' is not assignable to type 'Module | Class'.
44+
!!! error TS2322: Type 'Namespace' is not assignable to type 'Class'.
45+
!!! error TS2322: Property 'parent' is missing in type 'Namespace'.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//// [unionTypeWithRecursiveSubtypeReduction2.ts]
2+
class Module {
3+
public members: Class[];
4+
}
5+
6+
class Namespace {
7+
public members: (Class | Property)[];
8+
}
9+
10+
class Class {
11+
public parent: Namespace;
12+
}
13+
14+
class Property {
15+
public parent: Module | Class;
16+
}
17+
18+
var c: Class;
19+
var p: Property;
20+
c = p;
21+
p = c;
22+
23+
//// [unionTypeWithRecursiveSubtypeReduction2.js]
24+
var Module = (function () {
25+
function Module() {
26+
}
27+
return Module;
28+
})();
29+
var Namespace = (function () {
30+
function Namespace() {
31+
}
32+
return Namespace;
33+
})();
34+
var Class = (function () {
35+
function Class() {
36+
}
37+
return Class;
38+
})();
39+
var Property = (function () {
40+
function Property() {
41+
}
42+
return Property;
43+
})();
44+
var c;
45+
var p;
46+
c = p;
47+
p = c;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Module {
2+
public members: Class[];
3+
}
4+
5+
class Namespace {
6+
public members: (Class | Property)[];
7+
}
8+
9+
class Class {
10+
public parent: Namespace;
11+
}
12+
13+
class Property {
14+
public parent: Module | Class;
15+
}
16+
17+
var c: Class;
18+
var p: Property;
19+
c = p;
20+
p = c;

0 commit comments

Comments
 (0)