Skip to content

Handle old method signature in Alias/AnyMethod/Attr#1711

Open
Earlopain wants to merge 1 commit into
ruby:masterfrom
Earlopain:method-attr-compat
Open

Handle old method signature in Alias/AnyMethod/Attr#1711
Earlopain wants to merge 1 commit into
ruby:masterfrom
Earlopain:method-attr-compat

Conversation

@Earlopain
Copy link
Copy Markdown
Contributor

rbs for example uses them. This is not so pretty but can be reverted eventually. rbs tests pass with this.

Should I mention rdoc 8 in the warning? Not sure when you'd want to actually remove this.

Copilot AI review requested due to automatic review settings May 14, 2026 14:05
@Earlopain Earlopain requested a deployment to fork-preview-protection May 14, 2026 14:05 — with GitHub Actions Waiting
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Restores backward compatibility for callers (e.g. rbs) that still invoke RDoc::Alias, RDoc::AnyMethod, and RDoc::Attr with the old method signature carrying one extra leading positional argument. Each constructor now accepts a variadic positional list, emits a :deprecated warning when the legacy arity is detected, drops the obsolete leading argument, and raises ArgumentError for any other arity.

Changes:

  • Change RDoc::Alias#initialize, RDoc::AnyMethod#initialize, and RDoc::Attr#initialize to accept *args and dispatch on args.size.
  • Emit warn(..., uplevel: 1, category: :deprecated) when the old (extra-arg) signature is used, then shift off the leading argument.
  • Raise ArgumentError with a "given X, expected Y" message when the arity matches neither the new nor the legacy form.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/rdoc/code_object/alias.rb Accept legacy 4-arg form with deprecation warning; validate arity.
lib/rdoc/code_object/any_method.rb Accept legacy 2-arg form with deprecation warning; validate arity.
lib/rdoc/code_object/attr.rb Accept legacy 4-arg form with deprecation warning; validate arity.

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

raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 1)"
end

super(name = args[0], singleton: singleton)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For clarity this shows what this actually is. The other two assign it to named locals, here there is no such thing

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.

2 participants