Project

General

Profile

Actions

Bug #20866

closed

Prism assertion when running simplecov with branch coverage and requiring certain code

Added by Earlopain (Earlopain _) 18 days ago. Updated 2 days ago.

Status:
Closed
Assignee:
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-11-05T13:53:41Z master ed06f018bd) +PRISM [x86_64-linux]
[ruby-core:119735]

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
Actions #2

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

Actions #4

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:

  1. Create a file test.rb containing the following code
@foo&.(@bar)
  1. 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]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0