Skip to content

Improve alias redefinition warnings#9447

Merged
headius merged 5 commits into
jruby:masterfrom
headius:alias_redefinition_fixes
Jun 13, 2026
Merged

Improve alias redefinition warnings#9447
headius merged 5 commits into
jruby:masterfrom
headius:alias_redefinition_fixes

Conversation

@headius

@headius headius commented May 20, 2026

Copy link
Copy Markdown
Member

These warnings are firing a lot in Rails when they should not. The key piece is setting the aliased method's aliased bit so aliasing back doesn't warn, based on the hack in rails/rails#29233. This PR makes tweaks to handle that case and clean up related code.

headius added 2 commits May 20, 2026 00:48
Make these a single warning call to be a single write as in CRuby.
@headius headius added this to the JRuby 10.1.1.0 milestone May 20, 2026
headius added a commit to headius/jruby that referenced this pull request May 20, 2026
The exact old method should be marked as aliased, so if re-aliased
back again it won't trigger a warning.

See jruby#9447
This is CRuby behavior and Rails uses it as a hack for reverse-
aliasing methods without warnings.

See rails/rails#29233
Previous patch incorrectly checked the source method. This should
be squashed into that commit.
@headius

headius commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

Example case:

class Foo
  def foo end
  alias_method :bar, :foo
  define_method(:foo) {}
  alias_method :foo, :foo
  alias_method :foo, :bar
end

The self-aliasing here adds an alias bit to the foo method so that the subsequent alias_method call does not warn.

@headius
headius merged commit 63a0ede into jruby:master Jun 13, 2026
133 checks passed
@headius
headius deleted the alias_redefinition_fixes branch June 13, 2026 18:11
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.

1 participant