Actions
Bug #22269
open`Coverage.line_stub` clobbers already-collected coverage data
Bug #22269:
`Coverage.line_stub` clobbers already-collected coverage data
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-08-27T01:47:31Z master 5ee95de080) +PRISM [arm64-darwin25]
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:
Actual:
Updated by mugikurash (Shuta Mugikura) about 16 hours ago
Actions