Skip to content

Commit b551177

Browse files
committed
Merge pull request #3316 from Microsoft/circularInstantiatedTypes
Detect circular instantiated types
2 parents 4fd3bcf + 87d43aa commit b551177

File tree

6 files changed

+244
-78
lines changed

6 files changed

+244
-78
lines changed

Diff for: src/compiler/checker.ts

+66-72
Large diffs are not rendered by default.

Diff for: src/compiler/types.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1582,14 +1582,15 @@ module ts {
15821582
Tuple = 0x00002000, // Tuple
15831583
Union = 0x00004000, // Union
15841584
Anonymous = 0x00008000, // Anonymous
1585+
Instantiated = 0x00010000, // Instantiated anonymous type
15851586
/* @internal */
1586-
FromSignature = 0x00010000, // Created for signature assignment check
1587-
ObjectLiteral = 0x00020000, // Originates in an object literal
1587+
FromSignature = 0x00020000, // Created for signature assignment check
1588+
ObjectLiteral = 0x00040000, // Originates in an object literal
15881589
/* @internal */
1589-
ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type
1590+
ContainsUndefinedOrNull = 0x00080000, // Type is or contains Undefined or Null type
15901591
/* @internal */
1591-
ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type
1592-
ESSymbol = 0x00100000, // Type of symbol primitive introduced in ES6
1592+
ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type
1593+
ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6
15931594

15941595
/* @internal */
15951596
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
@@ -1731,7 +1732,6 @@ module ts {
17311732
/* @internal */
17321733
export interface TypeMapper {
17331734
(t: TypeParameter): Type;
1734-
mappings?: Map<Type>; // Type mapping cache
17351735
}
17361736

17371737
/* @internal */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [cyclicGenericTypeInstantiation.ts]
2+
function foo<T>() {
3+
var z = foo<typeof y>();
4+
var y: {
5+
y2: typeof z
6+
};
7+
return y;
8+
}
9+
10+
11+
function bar<T>() {
12+
var z = bar<typeof y>();
13+
var y: {
14+
y2: typeof z;
15+
}
16+
return y;
17+
}
18+
19+
var a = foo<number>();
20+
var b = bar<number>();
21+
a = b;
22+
23+
24+
//// [cyclicGenericTypeInstantiation.js]
25+
function foo() {
26+
var z = foo();
27+
var y;
28+
return y;
29+
}
30+
function bar() {
31+
var z = bar();
32+
var y;
33+
return y;
34+
}
35+
var a = foo();
36+
var b = bar();
37+
a = b;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts ===
2+
function foo<T>() {
3+
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0))
4+
>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 0, 13))
5+
6+
var z = foo<typeof y>();
7+
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7))
8+
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0))
9+
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7))
10+
11+
var y: {
12+
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7))
13+
14+
y2: typeof z
15+
>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 2, 12))
16+
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7))
17+
18+
};
19+
return y;
20+
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7))
21+
}
22+
23+
24+
function bar<T>() {
25+
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1))
26+
>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 9, 13))
27+
28+
var z = bar<typeof y>();
29+
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7))
30+
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1))
31+
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7))
32+
33+
var y: {
34+
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7))
35+
36+
y2: typeof z;
37+
>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 11, 12))
38+
>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7))
39+
}
40+
return y;
41+
>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7))
42+
}
43+
44+
var a = foo<number>();
45+
>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3))
46+
>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0))
47+
48+
var b = bar<number>();
49+
>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3))
50+
>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1))
51+
52+
a = b;
53+
>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3))
54+
>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3))
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts ===
2+
function foo<T>() {
3+
>foo : <T>() => { y2: any; }
4+
>T : T
5+
6+
var z = foo<typeof y>();
7+
>z : { y2: any; }
8+
>foo<typeof y>() : { y2: any; }
9+
>foo : <T>() => { y2: any; }
10+
>y : { y2: any; }
11+
12+
var y: {
13+
>y : { y2: any; }
14+
15+
y2: typeof z
16+
>y2 : { y2: any; }
17+
>z : { y2: any; }
18+
19+
};
20+
return y;
21+
>y : { y2: any; }
22+
}
23+
24+
25+
function bar<T>() {
26+
>bar : <T>() => { y2: any; }
27+
>T : T
28+
29+
var z = bar<typeof y>();
30+
>z : { y2: any; }
31+
>bar<typeof y>() : { y2: any; }
32+
>bar : <T>() => { y2: any; }
33+
>y : { y2: any; }
34+
35+
var y: {
36+
>y : { y2: any; }
37+
38+
y2: typeof z;
39+
>y2 : { y2: any; }
40+
>z : { y2: any; }
41+
}
42+
return y;
43+
>y : { y2: any; }
44+
}
45+
46+
var a = foo<number>();
47+
>a : { y2: any; }
48+
>foo<number>() : { y2: any; }
49+
>foo : <T>() => { y2: any; }
50+
51+
var b = bar<number>();
52+
>b : { y2: any; }
53+
>bar<number>() : { y2: any; }
54+
>bar : <T>() => { y2: any; }
55+
56+
a = b;
57+
>a = b : { y2: any; }
58+
>a : { y2: any; }
59+
>b : { y2: any; }
60+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function foo<T>() {
2+
var z = foo<typeof y>();
3+
var y: {
4+
y2: typeof z
5+
};
6+
return y;
7+
}
8+
9+
10+
function bar<T>() {
11+
var z = bar<typeof y>();
12+
var y: {
13+
y2: typeof z;
14+
}
15+
return y;
16+
}
17+
18+
var a = foo<number>();
19+
var b = bar<number>();
20+
a = b;

0 commit comments

Comments
 (0)