Bug #20866
closedPrism assertion when running simplecov with branch coverage and requiring certain code
Description
I stumbled upon the following bug report against simplecov: https://github.com/simplecov-ruby/simplecov/issues/1113
I reduced the error down to the following:
# Gemfile
source "https://rubygems.org"
gem "simplecov"
# test.rb
require "bundler"
require "simplecov"
SimpleCov.start do
enable_coverage :branch
end
require_relative "external"
# external.rb
def perform_completion
case @completion_state
when CompletionState::PERFECT_MATCH
@dig_perfect_match_proc&.(@perfect_matched)
end
end
$ bundle exec ruby test.rb
ruby: prism/util/pm_newline_list.c:93: pm_newline_list_line_column: Assertion `cursor >= list->start' failed.
Aborted (core dumped)
When running with parse.y
the error doesn't occur.
Updated by alanwu (Alan Wu) 18 days ago
- Assignee set to prism
Updated by hsbt (Hiroshi SHIBATA) 11 days ago
- Status changed from Open to Assigned
Updated by eightbitraptor (Matt V-H) 3 days ago
This was caused by an issue with how the prism compiler tracks the ending location of call nodes of the form a&.()
.
Should be fixed by this PR
Updated by eightbitraptor (Matt V-H) 2 days ago
- Status changed from Assigned to Closed
Applied in changeset git|680e06002666883537c05f796c31c6eacd6b4858.
[prism/compiler] end_cursor should never be NULL
This fixes a failed assertion reported to SimpleCov
https://github.com/simplecov-ruby/simplecov/issues/1113
This can be repro'd as follows:
- Create a file
test.rb
containing the following code
@foo&.(@bar)
- require it with branch coverage enabled
ruby -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
The assertion is failing because the Prism compiler is incorrectly
detecting the start and end cursor position of the call site for the
implicit call .()
This patch replicates the parse.y behaviour of setting the default
end_cursor to be the final closing location of the call node.
This behaviour can be verified against parse.y
by modifying the test
command as follows:
ruby --parser=parse.y -rcoverage -e "Coverage.start(branches: true); require_relative 'test.rb'"
[Bug #20866]