Commit ad32e93
fix(coverage): don't mark lines uncovered when zero-count range only partially overlaps (#32601)
## Summary
Fixes #13781 — `finally` blocks (and `if` condition lines) were
incorrectly marked as uncovered when all branches in `try`/`catch` had
`return` statements.
## Root cause
The coverage line count algorithm has two phases:
1. **Phase 1**: Find the innermost V8 range that *fully encloses* each
line → use its count
2. **Phase 2**: Reset count to 0 if *any* zero-count range merely
*overlaps* the line (even partially)
For `try`/`catch`/`finally` with returns, V8 emits a tiny zero-count
range (often just 1 character) representing the unreachable sequential
path between `catch`'s `return` and the `finally` keyword. Phase 2's
partial-overlap check let this tiny range incorrectly zero out the
`finally {` line — even though Phase 1 correctly found a larger
enclosing range with count > 0.
The same bug affected `if (cond) {` lines where the false-branch
zero-count range partially overlapped the condition line.
## Fix
Phase 2 now uses the same full-enclosure criterion as Phase 1, and only
overrides when the zero-count range is more specific (smaller) than the
best range found in Phase 1.
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 2989e30 commit ad32e93
3 files changed
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
340 | 344 | | |
341 | 345 | | |
342 | 346 | | |
| |||
345 | 349 | | |
346 | 350 | | |
347 | 351 | | |
348 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
349 | 355 | | |
350 | 356 | | |
351 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
0 commit comments