-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report unreachable on enums #58380
Draft
jakebailey
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
jakebailey:fix-58379
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Report unreachable on enums #58380
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/baselines/reference/unreachableEnum(preserveconstenums=false).errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
unreachableEnum.ts(4,17): error TS2450: Enum 'EnumA' used before its declaration. | ||
unreachableEnum.ts(14,5): error TS7027: Unreachable code detected. | ||
unreachableEnum.ts(21,17): error TS2450: Enum 'EnumA' used before its declaration. | ||
unreachableEnum.ts(29,5): error TS7027: Unreachable code detected. | ||
|
||
|
||
==== unreachableEnum.ts (4 errors) ==== | ||
function func1() { | ||
aFunc(); | ||
|
||
console.log(EnumA.Value); | ||
~~~~~ | ||
!!! error TS2450: Enum 'EnumA' used before its declaration. | ||
!!! related TS2728 unreachableEnum.ts:14:10: 'EnumA' is declared here. | ||
console.log(EnumB.Value); | ||
|
||
return; | ||
|
||
function aFunc() { | ||
console.log(EnumA.Value); | ||
console.log(EnumB.Value); | ||
} | ||
|
||
enum EnumA { Value } | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS7027: Unreachable code detected. | ||
const enum EnumB { Value } | ||
} | ||
|
||
function func2() { | ||
aFunc(); | ||
|
||
console.log(EnumA.Value); | ||
~~~~~ | ||
!!! error TS2450: Enum 'EnumA' used before its declaration. | ||
!!! related TS2728 unreachableEnum.ts:29:10: 'EnumA' is declared here. | ||
|
||
return; | ||
|
||
function aFunc() { | ||
console.log(EnumA.Value); | ||
} | ||
|
||
enum EnumA { Value } | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS7027: Unreachable code detected. | ||
} | ||
|
||
function func3() { | ||
aFunc(); | ||
|
||
console.log(EnumB.Value); | ||
|
||
return; | ||
|
||
function aFunc() { | ||
console.log(EnumB.Value); | ||
} | ||
|
||
const enum EnumB { Value } | ||
} |
84 changes: 84 additions & 0 deletions
84
tests/baselines/reference/unreachableEnum(preserveconstenums=false).js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//// [tests/cases/compiler/unreachableEnum.ts] //// | ||
|
||
//// [unreachableEnum.ts] | ||
function func1() { | ||
aFunc(); | ||
|
||
console.log(EnumA.Value); | ||
console.log(EnumB.Value); | ||
|
||
return; | ||
|
||
function aFunc() { | ||
console.log(EnumA.Value); | ||
console.log(EnumB.Value); | ||
} | ||
|
||
enum EnumA { Value } | ||
const enum EnumB { Value } | ||
} | ||
|
||
function func2() { | ||
aFunc(); | ||
|
||
console.log(EnumA.Value); | ||
|
||
return; | ||
|
||
function aFunc() { | ||
console.log(EnumA.Value); | ||
} | ||
|
||
enum EnumA { Value } | ||
} | ||
|
||
function func3() { | ||
aFunc(); | ||
|
||
console.log(EnumB.Value); | ||
|
||
return; | ||
|
||
function aFunc() { | ||
console.log(EnumB.Value); | ||
} | ||
|
||
const enum EnumB { Value } | ||
} | ||
|
||
//// [unreachableEnum.js] | ||
"use strict"; | ||
function func1() { | ||
aFunc(); | ||
console.log(EnumA.Value); | ||
console.log(0 /* EnumB.Value */); | ||
return; | ||
function aFunc() { | ||
console.log(EnumA.Value); | ||
console.log(0 /* EnumB.Value */); | ||
} | ||
var EnumA; | ||
(function (EnumA) { | ||
EnumA[EnumA["Value"] = 0] = "Value"; | ||
})(EnumA || (EnumA = {})); | ||
} | ||
function func2() { | ||
aFunc(); | ||
console.log(EnumA.Value); | ||
return; | ||
function aFunc() { | ||
console.log(EnumA.Value); | ||
} | ||
var EnumA; | ||
(function (EnumA) { | ||
EnumA[EnumA["Value"] = 0] = "Value"; | ||
})(EnumA || (EnumA = {})); | ||
} | ||
function func3() { | ||
aFunc(); | ||
console.log(0 /* EnumB.Value */); | ||
return; | ||
function aFunc() { | ||
console.log(0 /* EnumB.Value */); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
tests/baselines/reference/unreachableEnum(preserveconstenums=false).symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
//// [tests/cases/compiler/unreachableEnum.ts] //// | ||
|
||
=== unreachableEnum.ts === | ||
function func1() { | ||
>func1 : Symbol(func1, Decl(unreachableEnum.ts, 0, 0)) | ||
|
||
aFunc(); | ||
>aFunc : Symbol(aFunc, Decl(unreachableEnum.ts, 6, 11)) | ||
|
||
console.log(EnumA.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 13, 16)) | ||
>EnumA : Symbol(EnumA, Decl(unreachableEnum.ts, 11, 5)) | ||
>Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 13, 16)) | ||
|
||
console.log(EnumB.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 14, 22)) | ||
>EnumB : Symbol(EnumB, Decl(unreachableEnum.ts, 13, 24)) | ||
>Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 14, 22)) | ||
|
||
return; | ||
|
||
function aFunc() { | ||
>aFunc : Symbol(aFunc, Decl(unreachableEnum.ts, 6, 11)) | ||
|
||
console.log(EnumA.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 13, 16)) | ||
>EnumA : Symbol(EnumA, Decl(unreachableEnum.ts, 11, 5)) | ||
>Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 13, 16)) | ||
|
||
console.log(EnumB.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 14, 22)) | ||
>EnumB : Symbol(EnumB, Decl(unreachableEnum.ts, 13, 24)) | ||
>Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 14, 22)) | ||
} | ||
|
||
enum EnumA { Value } | ||
>EnumA : Symbol(EnumA, Decl(unreachableEnum.ts, 11, 5)) | ||
>Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 13, 16)) | ||
|
||
const enum EnumB { Value } | ||
>EnumB : Symbol(EnumB, Decl(unreachableEnum.ts, 13, 24)) | ||
>Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 14, 22)) | ||
} | ||
|
||
function func2() { | ||
>func2 : Symbol(func2, Decl(unreachableEnum.ts, 15, 1)) | ||
|
||
aFunc(); | ||
>aFunc : Symbol(aFunc, Decl(unreachableEnum.ts, 22, 11)) | ||
|
||
console.log(EnumA.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 28, 16)) | ||
>EnumA : Symbol(EnumA, Decl(unreachableEnum.ts, 26, 5)) | ||
>Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 28, 16)) | ||
|
||
return; | ||
|
||
function aFunc() { | ||
>aFunc : Symbol(aFunc, Decl(unreachableEnum.ts, 22, 11)) | ||
|
||
console.log(EnumA.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 28, 16)) | ||
>EnumA : Symbol(EnumA, Decl(unreachableEnum.ts, 26, 5)) | ||
>Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 28, 16)) | ||
} | ||
|
||
enum EnumA { Value } | ||
>EnumA : Symbol(EnumA, Decl(unreachableEnum.ts, 26, 5)) | ||
>Value : Symbol(EnumA.Value, Decl(unreachableEnum.ts, 28, 16)) | ||
} | ||
|
||
function func3() { | ||
>func3 : Symbol(func3, Decl(unreachableEnum.ts, 29, 1)) | ||
|
||
aFunc(); | ||
>aFunc : Symbol(aFunc, Decl(unreachableEnum.ts, 36, 11)) | ||
|
||
console.log(EnumB.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 42, 22)) | ||
>EnumB : Symbol(EnumB, Decl(unreachableEnum.ts, 40, 5)) | ||
>Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 42, 22)) | ||
|
||
return; | ||
|
||
function aFunc() { | ||
>aFunc : Symbol(aFunc, Decl(unreachableEnum.ts, 36, 11)) | ||
|
||
console.log(EnumB.Value); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 42, 22)) | ||
>EnumB : Symbol(EnumB, Decl(unreachableEnum.ts, 40, 5)) | ||
>Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 42, 22)) | ||
} | ||
|
||
const enum EnumB { Value } | ||
>EnumB : Symbol(EnumB, Decl(unreachableEnum.ts, 40, 5)) | ||
>Value : Symbol(EnumB.Value, Decl(unreachableEnum.ts, 42, 22)) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.