Project

General

Profile

Actions

Bug #22278

open

`Coverage.line_stub` emits warnings found in source code

Bug #22278: `Coverage.line_stub` emits warnings found in source code

Added by Earlopain (Earlopain _) 3 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:126539]

Description

Coverage.line_stub is implemented via RubyVM::InstructionSequence.compile_file. That emits all warnings found in the source code when $VERBOSE = true.

I found this via simplecov. It can do coverage for compiled erb, and it also shows files that have never been used in tests via the aforementioned method. When that file is erb on disk, then trying to interpret it as ruby gives a plethora of warnings. Probably simplecov should not do that with erb in the first place, but that's another story.

I started seeing this from 4.0.3 -> 4.0.4 so I guess it was because of https://bugs.ruby-lang.org/issues/22018

Here is a simple reproducer:

require "coverage"
require "tempfile"

$VERBOSE = true
Tempfile.open do |f|
  f.write(<<~RUBY)
    def foo
      x = 1
      true
    end
  RUBY
  f.close
  Coverage.line_stub(f.path)
end

# $ ruby test.rb 
# /tmp/20260828-2866859-62r0kn:2: warning: assigned but unused variable - x

No data to display

Actions

Also available in: PDF Atom