Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,12 @@ def add_module_or_class(module_name, start_line, end_line, is_class: false, supe
mod = owner.add_class(RDoc::NormalClass, name, superclass_name || superclass_expr || '::Object')
mod.ignore if document_suppressed? && mod.in_files.empty?
end
if superclass_name

# Superclass with the same full path and superclass for BasicObject are not allowed
if superclass_name && mod.full_name != superclass_full_path && mod.full_name != 'BasicObject'
if superclass
mod.superclass = superclass
elsif (mod.superclass.is_a?(String) || mod.superclass.name == 'Object') && mod.superclass != superclass_full_path
elsif mod.superclass.nil? || (mod.superclass.is_a?(String) || mod.superclass.name == 'Object') && mod.superclass != superclass_full_path
Comment on lines +910 to +914
mod.superclass = superclass_full_path
end
end
Expand Down
23 changes: 23 additions & 0 deletions test/rdoc/parser/ruby_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3023,6 +3023,29 @@ def bar(x); end
assert_match %r{:\d+: invalid RBS type signature: "\(String ->"}, err
end

def test_nil_superclass_case
# Context#add_class will create a class with nil superclass when
# the class is a BasicObject, or a superclass has the same full_name as the class itself.
# Superclass overwrite should follow this rule.
util_parser <<~RUBY
class BasicObject < Super; end
class BasicObject < Super; end
class Foo < Foo; end
class Bar < Bar; end
class Bar < Super; end
module M
class Baz < Super; end
class Baz < Baz; end
class Baz < M::Baz; end
end
RUBY

assert_nil @store.find_class_named('BasicObject').superclass
assert_nil @store.find_class_named('Foo').superclass
assert_equal 'Super', @store.find_class_named('Bar').superclass
assert_equal 'Super', @store.find_class_named('M::Baz').superclass
end
Comment on lines +3026 to +3047

def util_parser(content)
@parser = RDoc::Parser::Ruby.new @top_level, content, @options, @stats
@parser.scan
Expand Down