microsoft / microsoft/TypeScript
Exhaustive switch case with returns can mark a finally block as unreachable
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
finally switch exhaustive unreachable
🕗 Version & Regression Information
This is the behavior in every version I tried ( doesn't typecheck pre 3.7 ), and I reviewed the FAQ for entries about unreachable code
⏯ Playground Link
💻 Code
const c = (v: 1 | 2) => {
try {
switch (v) {
case 1: return v
case 2: return v
}
} finally {
if (true) {
console.log('exit')
}
}
}
🙁 Actual behavior
The contents of the finally blocked are marked as unreachable
🙂 Expected behavior
That they are reachable
Additional information about the issue
While the example seems to include some confusing additions the replication apparently requires:
- The cases to be exhaustive
- No default case
- For the switch expression be typed as a literal union of some form
- An
ifstatement to be in thefinallyblock
I assume this is a chaotic mix of unreachable patterns upsetting flow analysis. I've also noticed that it you add an unreachable return statement after the switch then the contents of finally become reachable.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現コードから始め、try/finally 内の網羅的な literal-union switch を、列挙されたバリエーション、つまり default case または switch の後にある到達不能な return と比較します。if 文を finally 内で到達不能と判定するフロー解析を追跡し、その後、finally の内容が到達可能であることを示すカバレッジを追加して、期待される diagnostics を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100