Fix coverage(eval) segfault when annotations are disabled#2553
Closed
joshsadam wants to merge 2 commits intoViewComponent:mainfrom
Closed
Fix coverage(eval) segfault when annotations are disabled#2553joshsadam wants to merge 2 commits intoViewComponent:mainfrom
joshsadam wants to merge 2 commits intoViewComponent:mainfrom
Conversation
joelhawksley
approved these changes
Feb 12, 2026
Author
|
This is not working the way I thought. I will get back to you on this fix. |
Member
|
@joshsadam thanks for digging into it. I just landed #2552 to main, can you rebase this branch and see if that fix worked for you? |
Author
|
That's great, thanks @joelhawksley I pinned your main branch in our gemfile, and running the CI tests now. I will let you know how it goes. |
Author
|
@joelhawksley our tests pass on CI now after pinning your main version. Can you do a minor release with this update? |
Member
|
@joshsadam yes, I'll be getting a release out today. Thank you for your help validating! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
Prevent a segfault when running with Ruby coverage of eval'd code enabled (for example
SimpleCov.enable_coverage_for_eval) on Rails 8.1 ERB templates withActionView::Base.annotate_rendered_view_with_filenames = false.The current logic can still pass
lineno = -1toclass_evalin this case, which triggers a Ruby crash in branch coverage instrumentation.What approach did you choose and why?
Two targeted changes:
Template::File, whencoverage_running?is true, always avoid negative line numbers by usinglineno = 0.ActionView::Base.annotate_rendered_view_with_filenamesso stack trace behavior remains unchanged where annotations are enabled.This preserves existing behavior outside of coverage mode while removing the crash path.
I also updated the regression helper to start coverage with
eval: true:Without
eval: true, the test does not exercise the crashing path.Anything you want to highlight for special attention from reviewers?
Context:
Minimal reproducer (outside ViewComponent):
On Ruby 3.4 this segfaults with a backtrace through
add_trace_branch_coverage.