Skip to content

Commit 76f2f2f

Browse files
committed
add test
1 parent 805972d commit 76f2f2f

6 files changed

+183
-10
lines changed

tests/baselines/reference/unreachableFlowAfterThrowingForHead2(allowunreachablecode=false).errors.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
unreachableFlowAfterThrowingForHead2.ts(10,7): error TS7027: Unreachable code detected.
1+
unreachableFlowAfterThrowingForHead2.ts(9,5): error TS7027: Unreachable code detected.
2+
unreachableFlowAfterThrowingForHead2.ts(22,7): error TS7027: Unreachable code detected.
23

34

4-
==== unreachableFlowAfterThrowingForHead2.ts (1 errors) ====
5+
==== unreachableFlowAfterThrowingForHead2.ts (2 errors) ====
56
function test1(v: 0 | 1 | 2) {
7+
for (
8+
(function () {
9+
throw new Error("");
10+
})();
11+
v;
12+
v++
13+
) {
14+
console.log("1");
15+
~~~~~~~~~~~~~~~~~
16+
!!! error TS7027: Unreachable code detected.
17+
}
18+
}
19+
20+
function test2(v: 0 | 1 | 2) {
621
try {
722
for (
823
(function () {

tests/baselines/reference/unreachableFlowAfterThrowingForHead2(allowunreachablecode=false).symbols

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ function test1(v: 0 | 1 | 2) {
55
>test1 : Symbol(test1, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 0))
66
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
77

8+
for (
9+
(function () {
10+
throw new Error("");
11+
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2022.error.d.ts, --, --))
12+
13+
})();
14+
v;
15+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
16+
17+
v++
18+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
19+
20+
) {
21+
console.log("1");
22+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
23+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
24+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
25+
}
26+
}
27+
28+
function test2(v: 0 | 1 | 2) {
29+
>test2 : Symbol(test2, Decl(unreachableFlowAfterThrowingForHead2.ts, 10, 1))
30+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
31+
832
try {
933
for (
1034
(function () {
@@ -13,10 +37,10 @@ function test1(v: 0 | 1 | 2) {
1337

1438
})();
1539
v;
16-
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
40+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
1741

1842
v++
19-
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
43+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
2044

2145
) {
2246
console.log("1");
@@ -25,9 +49,9 @@ function test1(v: 0 | 1 | 2) {
2549
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
2650
}
2751
} catch (e) {}
28-
>e : Symbol(e, Decl(unreachableFlowAfterThrowingForHead2.ts, 11, 11))
52+
>e : Symbol(e, Decl(unreachableFlowAfterThrowingForHead2.ts, 23, 11))
2953

3054
v;
31-
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
55+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
3256
}
3357

tests/baselines/reference/unreachableFlowAfterThrowingForHead2(allowunreachablecode=false).types

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,55 @@ function test1(v: 0 | 1 | 2) {
55
>test1 : (v: 0 | 1 | 2) => void
66
> : ^ ^^ ^^^^^^^^^
77
>v : 0 | 1 | 2
8+
> : ^^^^^^^^^
9+
10+
for (
11+
(function () {
12+
>(function () { throw new Error(""); })() : never
13+
> : ^^^^^
14+
>(function () { throw new Error(""); }) : () => never
15+
> : ^^^^^^^^^^^
16+
>function () { throw new Error(""); } : () => never
17+
> : ^^^^^^^^^^^
18+
19+
throw new Error("");
20+
>new Error("") : Error
21+
> : ^^^^^
22+
>Error : ErrorConstructor
23+
> : ^^^^^^^^^^^^^^^^
24+
>"" : ""
25+
> : ^^
26+
27+
})();
28+
v;
29+
>v : 0 | 1 | 2
30+
> : ^^^^^^^^^
31+
32+
v++
33+
>v++ : number
34+
> : ^^^^^^
35+
>v : number
36+
> : ^^^^^^
37+
38+
) {
39+
console.log("1");
40+
>console.log("1") : void
41+
> : ^^^^
42+
>console.log : (...data: any[]) => void
43+
> : ^^^^ ^^ ^^^^^
44+
>console : Console
45+
> : ^^^^^^^
46+
>log : (...data: any[]) => void
47+
> : ^^^^ ^^ ^^^^^
48+
>"1" : "1"
49+
> : ^^^
50+
}
51+
}
52+
53+
function test2(v: 0 | 1 | 2) {
54+
>test2 : (v: 0 | 1 | 2) => void
55+
> : ^ ^^ ^^^^^^^^^
56+
>v : 0 | 1 | 2
857
> : ^^^^^^^^^
958

1059
try {

tests/baselines/reference/unreachableFlowAfterThrowingForHead2(allowunreachablecode=true).symbols

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ function test1(v: 0 | 1 | 2) {
55
>test1 : Symbol(test1, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 0))
66
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
77

8+
for (
9+
(function () {
10+
throw new Error("");
11+
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2022.error.d.ts, --, --))
12+
13+
})();
14+
v;
15+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
16+
17+
v++
18+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
19+
20+
) {
21+
console.log("1");
22+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
23+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
24+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
25+
}
26+
}
27+
28+
function test2(v: 0 | 1 | 2) {
29+
>test2 : Symbol(test2, Decl(unreachableFlowAfterThrowingForHead2.ts, 10, 1))
30+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
31+
832
try {
933
for (
1034
(function () {
@@ -13,10 +37,10 @@ function test1(v: 0 | 1 | 2) {
1337

1438
})();
1539
v;
16-
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
40+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
1741

1842
v++
19-
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
43+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
2044

2145
) {
2246
console.log("1");
@@ -25,9 +49,9 @@ function test1(v: 0 | 1 | 2) {
2549
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
2650
}
2751
} catch (e) {}
28-
>e : Symbol(e, Decl(unreachableFlowAfterThrowingForHead2.ts, 11, 11))
52+
>e : Symbol(e, Decl(unreachableFlowAfterThrowingForHead2.ts, 23, 11))
2953

3054
v;
31-
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 0, 15))
55+
>v : Symbol(v, Decl(unreachableFlowAfterThrowingForHead2.ts, 12, 15))
3256
}
3357

tests/baselines/reference/unreachableFlowAfterThrowingForHead2(allowunreachablecode=true).types

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,55 @@ function test1(v: 0 | 1 | 2) {
55
>test1 : (v: 0 | 1 | 2) => void
66
> : ^ ^^ ^^^^^^^^^
77
>v : 0 | 1 | 2
8+
> : ^^^^^^^^^
9+
10+
for (
11+
(function () {
12+
>(function () { throw new Error(""); })() : never
13+
> : ^^^^^
14+
>(function () { throw new Error(""); }) : () => never
15+
> : ^^^^^^^^^^^
16+
>function () { throw new Error(""); } : () => never
17+
> : ^^^^^^^^^^^
18+
19+
throw new Error("");
20+
>new Error("") : Error
21+
> : ^^^^^
22+
>Error : ErrorConstructor
23+
> : ^^^^^^^^^^^^^^^^
24+
>"" : ""
25+
> : ^^
26+
27+
})();
28+
v;
29+
>v : 0 | 1 | 2
30+
> : ^^^^^^^^^
31+
32+
v++
33+
>v++ : number
34+
> : ^^^^^^
35+
>v : number
36+
> : ^^^^^^
37+
38+
) {
39+
console.log("1");
40+
>console.log("1") : void
41+
> : ^^^^
42+
>console.log : (...data: any[]) => void
43+
> : ^^^^ ^^ ^^^^^
44+
>console : Console
45+
> : ^^^^^^^
46+
>log : (...data: any[]) => void
47+
> : ^^^^ ^^ ^^^^^
48+
>"1" : "1"
49+
> : ^^^
50+
}
51+
}
52+
53+
function test2(v: 0 | 1 | 2) {
54+
>test2 : (v: 0 | 1 | 2) => void
55+
> : ^ ^^ ^^^^^^^^^
56+
>v : 0 | 1 | 2
857
> : ^^^^^^^^^
958

1059
try {

tests/cases/compiler/unreachableFlowAfterThrowingForHead2.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
// @allowUnreachableCode: true, false
44

55
function test1(v: 0 | 1 | 2) {
6+
for (
7+
(function () {
8+
throw new Error("");
9+
})();
10+
v;
11+
v++
12+
) {
13+
console.log("1");
14+
}
15+
}
16+
17+
function test2(v: 0 | 1 | 2) {
618
try {
719
for (
820
(function () {

0 commit comments

Comments
 (0)