From 994ee4c17fb8c217ab0335df55620c6bdb5d5cbe Mon Sep 17 00:00:00 2001 From: tompng Date: Fri, 26 Dec 2025 04:57:12 +0900 Subject: [PATCH] Fix comment_location for merged ClassModule --- lib/rdoc/code_object/class_module.rb | 7 ++++++- test/rdoc/code_object/class_module_test.rb | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index b6bed352a2..d7ee36f950 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -477,7 +477,12 @@ def merge(class_module) document = document.merge other_document @comment = RDoc::Comment.from_document(document) - @comment_location = document + + @comment_location = if document.parts.first.is_a?(RDoc::Markup::Document) + document.parts.map { |doc| [doc, doc.file] } + else + [[document, document.file]] + end end cm = class_module diff --git a/test/rdoc/code_object/class_module_test.rb b/test/rdoc/code_object/class_module_test.rb index 33fd4a67ad..b2ba4ebcf1 100644 --- a/test/rdoc/code_object/class_module_test.rb +++ b/test/rdoc/code_object/class_module_test.rb @@ -655,8 +655,10 @@ def test_merge tl = @store.add_file 'one.rb' p1 = tl.add_class RDoc::NormalClass, 'Parent' c1 = p1.add_class RDoc::NormalClass, 'Klass' + c1.add_comment 'comment1', tl c2 = RDoc::NormalClass.new 'Klass' + c2.add_comment 'comment2', tl c2.merge c1 @@ -665,6 +667,10 @@ def test_merge assert c1.current_section, 'original current_section' assert c2.current_section, 'merged current_section' + + comment, location = c2.comment_location.first + assert_kind_of RDoc::Markup::Document, comment + assert_equal tl.relative_name, location end def test_merge_attributes