Skip to content

Commit 3343bae

Browse files
committed
Add regression tests
1 parent d63bc8d commit 3343bae

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=== tests/cases/conformance/controlFlow/controlFlowNoIntermediateErrors.ts ===
2+
// Repros from #46475
3+
4+
function f1() {
5+
>f1 : Symbol(f1, Decl(controlFlowNoIntermediateErrors.ts, 0, 0))
6+
7+
let code: 0 | 1 | 2 = 0;
8+
>code : Symbol(code, Decl(controlFlowNoIntermediateErrors.ts, 3, 7))
9+
10+
const otherCodes: (0 | 1 | 2)[] = [2, 0, 1, 0, 2, 2, 2, 0, 1, 0, 2, 1, 1, 0, 2, 1];
11+
>otherCodes : Symbol(otherCodes, Decl(controlFlowNoIntermediateErrors.ts, 4, 9))
12+
13+
for (const code2 of otherCodes) {
14+
>code2 : Symbol(code2, Decl(controlFlowNoIntermediateErrors.ts, 5, 14))
15+
>otherCodes : Symbol(otherCodes, Decl(controlFlowNoIntermediateErrors.ts, 4, 9))
16+
17+
if (code2 === 0) {
18+
>code2 : Symbol(code2, Decl(controlFlowNoIntermediateErrors.ts, 5, 14))
19+
20+
code = code === 2 ? 1 : 0;
21+
>code : Symbol(code, Decl(controlFlowNoIntermediateErrors.ts, 3, 7))
22+
>code : Symbol(code, Decl(controlFlowNoIntermediateErrors.ts, 3, 7))
23+
}
24+
else {
25+
code = 2;
26+
>code : Symbol(code, Decl(controlFlowNoIntermediateErrors.ts, 3, 7))
27+
}
28+
}
29+
}
30+
31+
function f2() {
32+
>f2 : Symbol(f2, Decl(controlFlowNoIntermediateErrors.ts, 13, 1))
33+
34+
let code: 0 | 1 = 0;
35+
>code : Symbol(code, Decl(controlFlowNoIntermediateErrors.ts, 16, 7))
36+
37+
while (true) {
38+
code = code === 1 ? 0 : 1;
39+
>code : Symbol(code, Decl(controlFlowNoIntermediateErrors.ts, 16, 7))
40+
>code : Symbol(code, Decl(controlFlowNoIntermediateErrors.ts, 16, 7))
41+
}
42+
}
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
=== tests/cases/conformance/controlFlow/controlFlowNoIntermediateErrors.ts ===
2+
// Repros from #46475
3+
4+
function f1() {
5+
>f1 : () => void
6+
7+
let code: 0 | 1 | 2 = 0;
8+
>code : 0 | 1 | 2
9+
>0 : 0
10+
11+
const otherCodes: (0 | 1 | 2)[] = [2, 0, 1, 0, 2, 2, 2, 0, 1, 0, 2, 1, 1, 0, 2, 1];
12+
>otherCodes : (0 | 1 | 2)[]
13+
>[2, 0, 1, 0, 2, 2, 2, 0, 1, 0, 2, 1, 1, 0, 2, 1] : (0 | 1 | 2)[]
14+
>2 : 2
15+
>0 : 0
16+
>1 : 1
17+
>0 : 0
18+
>2 : 2
19+
>2 : 2
20+
>2 : 2
21+
>0 : 0
22+
>1 : 1
23+
>0 : 0
24+
>2 : 2
25+
>1 : 1
26+
>1 : 1
27+
>0 : 0
28+
>2 : 2
29+
>1 : 1
30+
31+
for (const code2 of otherCodes) {
32+
>code2 : 0 | 1 | 2
33+
>otherCodes : (0 | 1 | 2)[]
34+
35+
if (code2 === 0) {
36+
>code2 === 0 : boolean
37+
>code2 : 0 | 1 | 2
38+
>0 : 0
39+
40+
code = code === 2 ? 1 : 0;
41+
>code = code === 2 ? 1 : 0 : 0 | 1
42+
>code : 0 | 1 | 2
43+
>code === 2 ? 1 : 0 : 0 | 1
44+
>code === 2 : boolean
45+
>code : 0 | 1 | 2
46+
>2 : 2
47+
>1 : 1
48+
>0 : 0
49+
}
50+
else {
51+
code = 2;
52+
>code = 2 : 2
53+
>code : 0 | 1 | 2
54+
>2 : 2
55+
}
56+
}
57+
}
58+
59+
function f2() {
60+
>f2 : () => void
61+
62+
let code: 0 | 1 = 0;
63+
>code : 0 | 1
64+
>0 : 0
65+
66+
while (true) {
67+
>true : true
68+
69+
code = code === 1 ? 0 : 1;
70+
>code = code === 1 ? 0 : 1 : 0 | 1
71+
>code : 0 | 1
72+
>code === 1 ? 0 : 1 : 0 | 1
73+
>code === 1 : boolean
74+
>code : 0 | 1
75+
>1 : 1
76+
>0 : 0
77+
>1 : 1
78+
}
79+
}
80+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// Repros from #46475
5+
6+
function f1() {
7+
let code: 0 | 1 | 2 = 0;
8+
const otherCodes: (0 | 1 | 2)[] = [2, 0, 1, 0, 2, 2, 2, 0, 1, 0, 2, 1, 1, 0, 2, 1];
9+
for (const code2 of otherCodes) {
10+
if (code2 === 0) {
11+
code = code === 2 ? 1 : 0;
12+
}
13+
else {
14+
code = 2;
15+
}
16+
}
17+
}
18+
19+
function f2() {
20+
let code: 0 | 1 = 0;
21+
while (true) {
22+
code = code === 1 ? 0 : 1;
23+
}
24+
}

0 commit comments

Comments
 (0)