Skip to content

Commit c2431ad

Browse files
committed
Add regression test
1 parent 6995055 commit c2431ad

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [circularInferredTypeOfVariable.ts]
2+
3+
// Repro from #14428
4+
5+
(async () => {
6+
function foo(p: string[]): string[] {
7+
return [];
8+
}
9+
10+
function bar(p: string[]): string[] {
11+
return [];
12+
}
13+
14+
let a1: string[] | undefined = [];
15+
16+
while (true) {
17+
let a2 = foo(a1!);
18+
a1 = await bar(a2);
19+
}
20+
});
21+
22+
//// [circularInferredTypeOfVariable.js]
23+
// Repro from #14428
24+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25+
return new (P || (P = Promise))(function (resolve, reject) {
26+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
29+
step((generator = generator.apply(thisArg, _arguments || [])).next());
30+
});
31+
};
32+
(() => __awaiter(this, void 0, void 0, function* () {
33+
function foo(p) {
34+
return [];
35+
}
36+
function bar(p) {
37+
return [];
38+
}
39+
let a1 = [];
40+
while (true) {
41+
let a2 = foo(a1);
42+
a1 = yield bar(a2);
43+
}
44+
}));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/compiler/circularInferredTypeOfVariable.ts ===
2+
3+
// Repro from #14428
4+
5+
(async () => {
6+
function foo(p: string[]): string[] {
7+
>foo : Symbol(foo, Decl(circularInferredTypeOfVariable.ts, 3, 14))
8+
>p : Symbol(p, Decl(circularInferredTypeOfVariable.ts, 4, 17))
9+
10+
return [];
11+
}
12+
13+
function bar(p: string[]): string[] {
14+
>bar : Symbol(bar, Decl(circularInferredTypeOfVariable.ts, 6, 5))
15+
>p : Symbol(p, Decl(circularInferredTypeOfVariable.ts, 8, 17))
16+
17+
return [];
18+
}
19+
20+
let a1: string[] | undefined = [];
21+
>a1 : Symbol(a1, Decl(circularInferredTypeOfVariable.ts, 12, 7))
22+
23+
while (true) {
24+
let a2 = foo(a1!);
25+
>a2 : Symbol(a2, Decl(circularInferredTypeOfVariable.ts, 15, 11))
26+
>foo : Symbol(foo, Decl(circularInferredTypeOfVariable.ts, 3, 14))
27+
>a1 : Symbol(a1, Decl(circularInferredTypeOfVariable.ts, 12, 7))
28+
29+
a1 = await bar(a2);
30+
>a1 : Symbol(a1, Decl(circularInferredTypeOfVariable.ts, 12, 7))
31+
>bar : Symbol(bar, Decl(circularInferredTypeOfVariable.ts, 6, 5))
32+
>a2 : Symbol(a2, Decl(circularInferredTypeOfVariable.ts, 15, 11))
33+
}
34+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=== tests/cases/compiler/circularInferredTypeOfVariable.ts ===
2+
3+
// Repro from #14428
4+
5+
(async () => {
6+
>(async () => { function foo(p: string[]): string[] { return []; } function bar(p: string[]): string[] { return []; } let a1: string[] | undefined = []; while (true) { let a2 = foo(a1!); a1 = await bar(a2); }}) : () => Promise<never>
7+
>async () => { function foo(p: string[]): string[] { return []; } function bar(p: string[]): string[] { return []; } let a1: string[] | undefined = []; while (true) { let a2 = foo(a1!); a1 = await bar(a2); }} : () => Promise<never>
8+
9+
function foo(p: string[]): string[] {
10+
>foo : (p: string[]) => string[]
11+
>p : string[]
12+
13+
return [];
14+
>[] : undefined[]
15+
}
16+
17+
function bar(p: string[]): string[] {
18+
>bar : (p: string[]) => string[]
19+
>p : string[]
20+
21+
return [];
22+
>[] : undefined[]
23+
}
24+
25+
let a1: string[] | undefined = [];
26+
>a1 : string[]
27+
>[] : undefined[]
28+
29+
while (true) {
30+
>true : true
31+
32+
let a2 = foo(a1!);
33+
>a2 : string[]
34+
>foo(a1!) : string[]
35+
>foo : (p: string[]) => string[]
36+
>a1! : string[]
37+
>a1 : string[]
38+
39+
a1 = await bar(a2);
40+
>a1 = await bar(a2) : string[]
41+
>a1 : string[]
42+
>await bar(a2) : string[]
43+
>bar(a2) : string[]
44+
>bar : (p: string[]) => string[]
45+
>a2 : string[]
46+
}
47+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @target: es6
2+
3+
// Repro from #14428
4+
5+
(async () => {
6+
function foo(p: string[]): string[] {
7+
return [];
8+
}
9+
10+
function bar(p: string[]): string[] {
11+
return [];
12+
}
13+
14+
let a1: string[] | undefined = [];
15+
16+
while (true) {
17+
let a2 = foo(a1!);
18+
a1 = await bar(a2);
19+
}
20+
});

0 commit comments

Comments
 (0)