Fix alias detection for multiple rb_define_singleton_method#1732
Open
Earlopain wants to merge 2 commits into
Open
Fix alias detection for multiple rb_define_singleton_method#1732Earlopain wants to merge 2 commits into
rb_define_singleton_method#1732Earlopain wants to merge 2 commits into
Conversation
Earlopain
had a problem deploying
to
fork-preview-protection
June 16, 2026 10:56 — with
GitHub Actions
Failure
Contributor
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.
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
force-pushed
the
c-singleton-method-detection
branch
from
June 16, 2026 11:01
b343fe6 to
1054ba6
Compare
Earlopain
had a problem deploying
to
fork-preview-protection
June 16, 2026 11:01 — with
GitHub Actions
Failure
tompng
reviewed
Jul 18, 2026
| @@ -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 } | |||
Member
There was a problem hiding this comment.
I think it is better to also check singleton here.
Suggested change
| 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 } |
Contributor
Author
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.
Earlopain
requested a deployment
to
fork-preview-protection
July 18, 2026 20:17 — with
GitHub Actions
Waiting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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