Handle old method signature in Alias/AnyMethod/Attr#1711
Conversation
`rbs` for example uses them.
There was a problem hiding this comment.
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, andRDoc::Attr#initializeto accept*argsand dispatch onargs.size. - Emit
warn(..., uplevel: 1, category: :deprecated)when the old (extra-arg) signature is used, then shift off the leading argument. - Raise
ArgumentErrorwith 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) |
There was a problem hiding this comment.
For clarity this shows what this actually is. The other two assign it to named locals, here there is no such thing
rbsfor example uses them. This is not so pretty but can be reverted eventually.rbstests pass with this.Should I mention rdoc 8 in the warning? Not sure when you'd want to actually remove this.