Skip to content

Commit 3a8d6df

Browse files
authored
Fix full name of known class
Properly set the name of `File::Constants`, which is the only name with a namespace in `RDoc::KNOWN_CLASSES`, and fixes longstanding bug that `File::Constants` becomes `File::File::Constants`. When it is generated by `rb_file_const` in dir.c, `name` is set to the qualified name as same as `full_name`, and generated in the normal way in file.c later, already set `full_name` is cleared and `name` will be constructed from the enclosing namespace and the `name`. It will results in duplicated namespace, `File::File::Constants`.
1 parent c5ce8e5 commit 3a8d6df

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/rdoc/parser/c.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,14 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
667667
##
668668
# Finds a RDoc::NormalClass or RDoc::NormalModule for +raw_name+
669669

670-
def find_class(raw_name, name)
670+
def find_class(raw_name, name, base_name = nil)
671671
unless @classes[raw_name]
672672
if raw_name =~ /^rb_m/
673673
container = @top_level.add_module RDoc::NormalModule, name
674674
else
675675
container = @top_level.add_class RDoc::NormalClass, name
676676
end
677+
container.name = base_name if base_name
677678

678679
container.record_location @top_level
679680
@classes[raw_name] = container
@@ -911,7 +912,7 @@ def handle_constants(type, var_name, const_name, definition)
911912

912913
return unless class_name
913914

914-
class_obj = find_class var_name, class_name
915+
class_obj = find_class var_name, class_name, class_name[/::\K[^:]+\z/]
915916

916917
unless class_obj then
917918
@options.warn 'Enclosing class or module %p is not known' % [const_name]

test/rdoc/test_rdoc_parser_c.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,17 @@ def test_do_constants_file
638638
assert_equal 'LOCK_SH', constant.name
639639
assert_equal 'INT2FIX(LOCK_SH)', constant.value
640640
assert_equal 'Shared lock', constant.comment.text
641+
642+
@parser = util_parser <<-EOF
643+
void Init_File(void) {
644+
rb_cFile = rb_define_class("File", rb_cIO);
645+
rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
646+
}
647+
EOF
648+
@parser.do_classes_and_modules
649+
@parser.do_constants
650+
651+
assert_equal 'File::Constants', klass.full_name
641652
end
642653

643654
def test_do_includes

0 commit comments

Comments
 (0)