Project

General

Profile

Actions

Bug #22269

open

`Coverage.line_stub` clobbers already-collected coverage data

Bug #22269: `Coverage.line_stub` clobbers already-collected coverage data

Added by mugikurash (Shuta Mugikura) 1 day ago. Updated 1 day ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-08-27T01:47:31Z master 5ee95de080) +PRISM [arm64-darwin25]
[ruby-core:126513]

Description

Coverage.line_stub compiles the file with compile_file only to read the ISeq's trace_points. Since https://bugs.ruby-lang.org/issues/22018 compile_file registers the file into the coverage table, so calling line_stub while Coverage is running resets the file's already-collected counters.

This also reproduces on 3.4 and 4.0, so I would like it backported.

Reproduction:

require "coverage"

f = File.expand_path("m.rb")
File.write(f, "def m\n  :ok\nend\n")

Coverage.start
require f
m
p Coverage.peek_result[f]

Coverage.line_stub(f)
p Coverage.peek_result[f]

m
p Coverage.result[f]

Expected:

[1, 1, nil]
[1, 1, nil]
[1, 2, nil]

Actual:

[1, 1, nil]
[0, 0, nil]
[0, 0, nil]
Actions

Also available in: PDF Atom