diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d143606be..207b02718 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 6 ## main +* Fix segfault when coverage of eval'd code is enabled with Rails 8.1 ERB templates and view annotations are disabled. + + *Josh Adam* + * Add `protocol` parameter to `with_request_url` test helper to enable testing with HTTPS protocol. *Joel Hawksley* diff --git a/lib/view_component/template.rb b/lib/view_component/template.rb index afa1f8aec..f7c484dd6 100644 --- a/lib/view_component/template.rb +++ b/lib/view_component/template.rb @@ -137,8 +137,10 @@ def defined_on_self? def compile_to_component @component.silence_redefinition_of_method(call_method_name) + safe_lineno = coverage_running? && @lineno.to_i.negative? ? 1 : @lineno + # rubocop:disable Style/EvalWithLocation - @component.class_eval <<~RUBY, @path, @lineno + @component.class_eval <<~RUBY, @path, safe_lineno def #{call_method_name} #{compiled_source} end diff --git a/test/sandbox/test/inline_template_test.rb b/test/sandbox/test/inline_template_test.rb index 60fa38adf..0a8d1083f 100644 --- a/test/sandbox/test/inline_template_test.rb +++ b/test/sandbox/test/inline_template_test.rb @@ -234,7 +234,7 @@ class InlineComponentDerivedFromComponentSupportingVariants < Level2Component def with_coverage_running require "coverage" already_running = Coverage.running? - Coverage.start unless already_running + Coverage.start(lines: true, branches: true, eval: true) unless already_running yield ensure Coverage.result unless already_running