Skip to content

Commit 652a3a4

Browse files
committed
do not report 'unreachable code' on empty statements
1 parent 2c64447 commit 652a3a4

File tree

6 files changed

+29
-39
lines changed

6 files changed

+29
-39
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,8 @@ namespace ts {
14531453
switch (currentReachabilityState) {
14541454
case Reachability.Unreachable:
14551455
const reportError =
1456-
// report error on all statements
1457-
isStatement(node) ||
1456+
// report error on all statements except empty ones
1457+
(isStatement(node) && node.kind !== SyntaxKind.EmptyStatement) ||
14581458
// report error on class declarations
14591459
node.kind === SyntaxKind.ClassDeclaration ||
14601460
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [noReachabilityErrorsOnEmptyStatement.ts]
2+
function foo() {
3+
return 1;;
4+
}
5+
6+
//// [noReachabilityErrorsOnEmptyStatement.js]
7+
function foo() {
8+
return 1;
9+
;
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/noReachabilityErrorsOnEmptyStatement.ts ===
2+
function foo() {
3+
>foo : Symbol(foo, Decl(noReachabilityErrorsOnEmptyStatement.ts, 0, 0))
4+
5+
return 1;;
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/noReachabilityErrorsOnEmptyStatement.ts ===
2+
function foo() {
3+
>foo : () => number
4+
5+
return 1;;
6+
>1 : number
7+
}

tests/baselines/reference/privacyFunctionCannotNameReturnTypeDeclFile.errors.txt

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(3,12): error TS4050: Return type of public static method from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named.
2-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(7,49): error TS7027: Unreachable code detected.
32
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(9,5): error TS4053: Return type of public method from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named.
4-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(10,49): error TS7027: Unreachable code detected.
5-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(13,49): error TS7027: Unreachable code detected.
63
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(15,12): error TS4050: Return type of public static method from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named.
7-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(19,49): error TS7027: Unreachable code detected.
84
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(21,5): error TS4053: Return type of public method from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named.
9-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(22,49): error TS7027: Unreachable code detected.
10-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(25,49): error TS7027: Unreachable code detected.
11-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(34,49): error TS7027: Unreachable code detected.
12-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(37,49): error TS7027: Unreachable code detected.
13-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(40,49): error TS7027: Unreachable code detected.
14-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(46,49): error TS7027: Unreachable code detected.
15-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(49,49): error TS7027: Unreachable code detected.
16-
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(52,49): error TS7027: Unreachable code detected.
175
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(56,17): error TS4058: Return type of exported function has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named.
186
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(62,17): error TS4058: Return type of exported function has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named.
197
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(70,12): error TS4050: Return type of public static method from exported class has or is using name 'SpecializedWidget.Widget2' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named.
@@ -24,7 +12,7 @@ tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(83,17): error
2412
tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(86,17): error TS4058: Return type of exported function has or is using name 'SpecializedGlobalWidget.Widget4' from external module "GlobalWidgets" but cannot be named.
2513

2614

27-
==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts (24 errors) ====
15+
==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts (12 errors) ====
2816
import exporter = require("./privacyFunctionReturnTypeDeclFile_exporter");
2917
export class publicClassWithWithPrivateParmeterTypes {
3018
static myPublicStaticMethod() { // Error
@@ -34,20 +22,14 @@ tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(86,17): error
3422
}
3523
private static myPrivateStaticMethod() {
3624
return exporter.createExportedWidget1();;
37-
~
38-
!!! error TS7027: Unreachable code detected.
3925
}
4026
myPublicMethod() { // Error
4127
~~~~~~~~~~~~~~
4228
!!! error TS4053: Return type of public method from exported class has or is using name 'Widget1' from external module "tests/cases/compiler/privacyFunctionReturnTypeDeclFile_Widgets" but cannot be named.
4329
return exporter.createExportedWidget1();;
44-
~
45-
!!! error TS7027: Unreachable code detected.
4630
}
4731
private myPrivateMethod() {
4832
return exporter.createExportedWidget1();;
49-
~
50-
!!! error TS7027: Unreachable code detected.
5133
}
5234
static myPublicStaticMethod1() { // Error
5335
~~~~~~~~~~~~~~~~~~~~~
@@ -56,20 +38,14 @@ tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(86,17): error
5638
}
5739
private static myPrivateStaticMethod1() {
5840
return exporter.createExportedWidget3();;
59-
~
60-
!!! error TS7027: Unreachable code detected.
6141
}
6242
myPublicMethod1() { // Error
6343
~~~~~~~~~~~~~~~
6444
!!! error TS4053: Return type of public method from exported class has or is using name 'Widget3' from external module "GlobalWidgets" but cannot be named.
6545
return exporter.createExportedWidget3();;
66-
~
67-
!!! error TS7027: Unreachable code detected.
6846
}
6947
private myPrivateMethod1() {
7048
return exporter.createExportedWidget3();;
71-
~
72-
!!! error TS7027: Unreachable code detected.
7349
}
7450
}
7551

@@ -79,36 +55,24 @@ tests/cases/compiler/privacyFunctionReturnTypeDeclFile_consumer.ts(86,17): error
7955
}
8056
private static myPrivateStaticMethod() {
8157
return exporter.createExportedWidget1();;
82-
~
83-
!!! error TS7027: Unreachable code detected.
8458
}
8559
myPublicMethod() {
8660
return exporter.createExportedWidget1();;
87-
~
88-
!!! error TS7027: Unreachable code detected.
8961
}
9062
private myPrivateMethod() {
9163
return exporter.createExportedWidget1();;
92-
~
93-
!!! error TS7027: Unreachable code detected.
9464
}
9565
static myPublicStaticMethod1() {
9666
return exporter.createExportedWidget3();
9767
}
9868
private static myPrivateStaticMethod1() {
9969
return exporter.createExportedWidget3();;
100-
~
101-
!!! error TS7027: Unreachable code detected.
10270
}
10371
myPublicMethod1() {
10472
return exporter.createExportedWidget3();;
105-
~
106-
!!! error TS7027: Unreachable code detected.
10773
}
10874
private myPrivateMethod1() {
10975
return exporter.createExportedWidget3();;
110-
~
111-
!!! error TS7027: Unreachable code detected.
11276
}
11377
}
11478

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function foo() {
2+
return 1;;
3+
}

0 commit comments

Comments
 (0)