Fix alias detection for multiple rb_define_singleton_method#1732
Conversation
There was a problem hiding this comment.
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 inhandle_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.
| 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
b343fe6 to
1054ba6
Compare
| @@ -996,7 +996,7 @@ def handle_method(type, var_name, meth_name, function, param_count, | |||
| class_obj = find_class var_name, class_name | |||
|
|
|||
| if existing_method = class_obj.method_list.find { |m| m.c_function == function } | |||
There was a problem hiding this comment.
I think it is better to also check singleton here.
| if existing_method = class_obj.method_list.find { |m| m.c_function == function } | |
| if existing_method = class_obj.method_list.find { |m| m.c_function == function && m.singleton == singleton } |
There was a problem hiding this comment.
Sure, added a test for that. It passed before already though it did call add_alias which is unexpected.
It currently calls `add_alias` for the added test, although it already works out correctly regardless.
|
🚀 Preview deployment available at: https://ab84fa24.rdoc-6cd.pages.dev (commit: 749faae) |
They were not detected because
singleton_classesdoesn't contain the variable. Fix this simply by moving the check forsingleton_methodfurther up.Closes #1722
List of affected classes