Skip to content

Fix alias detection for multiple rb_define_singleton_method#1732

Open
Earlopain wants to merge 1 commit into
ruby:masterfrom
Earlopain:c-singleton-method-detection
Open

Fix alias detection for multiple rb_define_singleton_method#1732
Earlopain wants to merge 1 commit into
ruby:masterfrom
Earlopain:c-singleton-method-detection

Conversation

@Earlopain

@Earlopain Earlopain commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

They were not detected because singleton_classes doesn't contain the variable. Fix this simply by moving the check for singleton_method further up.

Closes #1722

List of affected classes

Complex
Date
DateTime
Dir
ENV
File
Pathname
Process
Regexp
Socket
Thread
UNIXSocket
Fiddle::Handle
RubyVM::InstructionSequence

grafik grafik

Copilot AI review requested due to automatic review settings June 16, 2026 10:56
@Earlopain Earlopain requested a deployment to fork-preview-protection June 16, 2026 10:56 — with GitHub Actions Waiting

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the RDoc C parser’s alias handling so aliases created from duplicate C function definitions correctly preserve singleton/instance context, and expands tests to cover both instance and singleton scenarios.

Changes:

  • Rename alias-related tests to distinguish instance vs singleton cases.
  • Add new tests for “duplicate rb_define_method / rb_define_singleton_method” aliasing behavior.
  • Update alias creation to accept an explicit singleton: value and broaden singleton detection in handle_method.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/rdoc/parser/c_test.rb Renames existing alias tests and adds coverage for duplicate-define alias generation for instance and singleton methods.
lib/rdoc/parser/c.rb Passes explicit singleton context when creating aliases and fixes singleton detection for singleton_method / module_function types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/rdoc/parser/c_test.rb
Comment on lines +249 to +261
def test_do_instance_duplicate_define_method
content = <<~C
VALUE blah(VALUE klass, VALUE year) {
}

void Init_Blah(void) {
cDate = rb_define_class("Date", rb_cObject);

rb_define_method(cDate, "blah", blah, 1);

rb_define_method(cDate, "bleh", blah, 1);
}
C
They were not detected because `singleton_classes` doesn't contain the variable.
Fix this simply by moving the check for `singleton_method` further up.

Closes ruby#1722
@Earlopain Earlopain force-pushed the c-singleton-method-detection branch from b343fe6 to 1054ba6 Compare June 16, 2026 11:01
@Earlopain Earlopain requested a deployment to fork-preview-protection June 16, 2026 11:01 — with GitHub Actions Waiting
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.

Dir.getwd shows Dir.pwd as its name

2 participants