Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prism_ruby superclass resolve order #1267

Merged
merged 1 commit into from
Jan 3, 2025
Merged
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/prism_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,16 @@ def add_module_or_class(module_name, start_line, end_line, is_class: false, supe

owner, name = find_or_create_constant_owner_name(module_name)
if is_class
mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || '::Object')

# RDoc::NormalClass resolves superclass name despite of the lack of module nesting information.
# We need to fix it when RDoc::NormalClass resolved to a wrong constant name
if superclass_name
superclass_full_path = resolve_constant_path(superclass_name)
superclass = @store.find_class_or_module(superclass_full_path) if superclass_full_path
superclass_full_path ||= superclass_name
end
# add_class should be done after resolving superclass
mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || '::Object')
if superclass_name
if superclass
mod.superclass = superclass
elsif mod.superclass.is_a?(String) && mod.superclass != superclass_full_path
Expand Down
19 changes: 19 additions & 0 deletions test/rdoc/test_rdoc_parser_prism_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ class A::C4 < A::B; end
assert_equal ['A::B', 'A::B', 'A::A::B', 'A::B'], classes.drop(1).map(&:superclass).map(&:full_name)
end

def test_pseudo_recursive_superclass
util_parser <<~RUBY
module Foo
class Bar
class Foo < Bar; end
# This class definition is used in OpenSSL::Cipher::Cipher
class Bar < Bar; end
class Baz < Bar; end
end
end
RUBY
foo_klass = @store.find_class_named 'Foo::Bar::Foo'
bar_klass = @store.find_class_named 'Foo::Bar::Bar'
baz_klass = @store.find_class_named 'Foo::Bar::Baz'
assert_equal 'Foo::Bar', foo_klass.superclass.full_name
assert_equal 'Foo::Bar', bar_klass.superclass.full_name
assert_equal 'Foo::Bar::Bar', baz_klass.superclass.full_name
end

def test_class_module_nodoc
util_parser <<~RUBY
class Foo # :nodoc:
Expand Down
Loading