Commit 6ba7d59
committed
Fix #3891: don't reduce nesting when there is no else block
ReduceNesting walks an else-if chain to its innermost if and asks
ShouldReduceNesting whether to extract the else block, which ExtractElseBlock
does by casting the block to Block. A chain with no trailing else reaches this
with a bare Nop, yet the heuristic still approved it (its stats count a Nop as
one statement), so the cast threw InvalidCastException. Take a Block in
ShouldReduceNesting and skip the reduction at the call site when the else is
absent.
Assisted-by: Claude:claude-opus-4-8:Claude Code1 parent 9ff3ac9 commit 6ba7d59
1 file changed
Lines changed: 7 additions & 5 deletions
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
| |||
582 | 584 | | |
583 | 585 | | |
584 | 586 | | |
585 | | - | |
| 587 | + | |
586 | 588 | | |
587 | | - | |
| 589 | + | |
588 | 590 | | |
589 | 591 | | |
590 | 592 | | |
591 | | - | |
| 593 | + | |
592 | 594 | | |
593 | 595 | | |
594 | | - | |
| 596 | + | |
595 | 597 | | |
596 | 598 | | |
597 | 599 | | |
| |||
0 commit comments