Skip to content

Commit

Permalink
Fix full name of known class
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
nobu committed Mar 16, 2022
1 parent c5ce8e5 commit 3a8d6df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rdoc/parser/c.rb
Expand Up @@ -667,13 +667,14 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
##
# Finds a RDoc::NormalClass or RDoc::NormalModule for +raw_name+

def find_class(raw_name, name)
def find_class(raw_name, name, base_name = nil)
unless @classes[raw_name]
if raw_name =~ /^rb_m/
container = @top_level.add_module RDoc::NormalModule, name
else
container = @top_level.add_class RDoc::NormalClass, name
end
container.name = base_name if base_name

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

return unless class_name

class_obj = find_class var_name, class_name
class_obj = find_class var_name, class_name, class_name[/::\K[^:]+\z/]

unless class_obj then
@options.warn 'Enclosing class or module %p is not known' % [const_name]
Expand Down
11 changes: 11 additions & 0 deletions test/rdoc/test_rdoc_parser_c.rb
Expand Up @@ -638,6 +638,17 @@ def test_do_constants_file
assert_equal 'LOCK_SH', constant.name
assert_equal 'INT2FIX(LOCK_SH)', constant.value
assert_equal 'Shared lock', constant.comment.text

@parser = util_parser <<-EOF
void Init_File(void) {
rb_cFile = rb_define_class("File", rb_cIO);
rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
}
EOF
@parser.do_classes_and_modules
@parser.do_constants

assert_equal 'File::Constants', klass.full_name
end

def test_do_includes
Expand Down

0 comments on commit 3a8d6df

Please sign in to comment.