Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Nov 18, 2025

Fixes #1440
Always track class and singleton class stored to a variable to @classes.
Otherwise, find_class var_name, class_name called from handle_method will add a new class.

Before:
before
After:
after

Minimal reproduction:

VALUE mFoo = rb_define_module("Foo");
VALUE mBar = rb_define_module_under(mFoo, "Bar");
VALUE mBarS = rb_singleton_class(mBar);
rb_define_method(mBarS, "baz", baz, 0);

RDoc::Parser::C#handle_method calls find_class 'mBarS', 'Foo::Bar'.
RDoc::Parser::C#find_class calls @top_level.add_class RDoc::NormalClass, 'Foo::Bar'. This will create ::Bar for some reason and Foo::Bar disappears from generated document.

@tompng tompng requested a deployment to fork-preview-protection November 18, 2025 18:56 — with GitHub Actions Waiting
@tompng tompng force-pushed the fix_c_singleton_handling branch from fa630f0 to 2c33648 Compare November 18, 2025 19:17
@tompng tompng requested a deployment to fork-preview-protection November 18, 2025 19:17 — with GitHub Actions Waiting
@tompng tompng force-pushed the fix_c_singleton_handling branch from 2c33648 to c591a67 Compare November 18, 2025 19:18
@tompng tompng requested a deployment to fork-preview-protection November 18, 2025 19:20 — with GitHub Actions Waiting
Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

…sted module name

Always track class and singleton class stored to a variable to `@classes`.
Otherwise, `find_class var_name, class_name` called from `handle_method` will add a new class to `@toplevel`.
@tompng tompng force-pushed the fix_c_singleton_handling branch from c591a67 to 58e0fd8 Compare November 19, 2025 04:55
@tompng tompng requested a deployment to fork-preview-protection November 19, 2025 04:55 — with GitHub Actions Waiting
@tompng tompng merged commit fcb515f into ruby:master Nov 19, 2025
31 of 32 checks passed
@tompng tompng deleted the fix_c_singleton_handling branch November 19, 2025 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate entries in "Class and Module Index"

3 participants