Skip to content

Deprecate the fallback to Object for alias in a module - #18740

Merged
shugo merged 1 commit into
ruby:masterfrom
shugo:fix/deprecate-alias-object-fallback
Sep 17, 2026
Merged

shugo merged 1 commit into
ruby:masterfrom
shugo:fix/deprecate-alias-object-fallback

Conversation

@shugo

@shugo shugo commented Sep 10, 2026

Copy link
Copy Markdown
Member

alias and Module#alias_method in a module fall back to searching the method from Object when the module and its ancestors do not have it. The fallback assumes Object is the root class, which is no longer true since BasicObject was introduced in 1.9, so Matz decided to remove it. As the first step, warn in verbose mode when the fallback is used; the plan is to warn unconditionally in 4.2 and to raise NameError in 4.3.

https://bugs.ruby-lang.org/issues/22276

@shugo
shugo marked this pull request as ready for review September 10, 2026 11:01
@shugo
shugo force-pushed the fix/deprecate-alias-object-fallback branch from 9768d87 to 341585b Compare September 11, 2026 00:29
`alias` and `Module#alias_method` in a module fall back to searching
the method from Object when the module and its ancestors do not have
it. The fallback assumes Object is the root class, which is no longer
true since BasicObject was introduced in 1.9, so Matz decided to
remove it. As the first step, warn in verbose mode when the fallback
is used; the plan is to warn unconditionally in 4.2 and to raise
NameError in 4.3.

https://bugs.ruby-lang.org/issues/22276

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shugo
shugo force-pushed the fix/deprecate-alias-object-fallback branch from 341585b to 5de05df Compare September 17, 2026 01:06
@shugo
shugo enabled auto-merge (rebase) September 17, 2026 01:06
@shugo
shugo merged commit 1c0b1be into ruby:master Sep 17, 2026
138 of 140 checks passed
yahonda added a commit to rails/rails that referenced this pull request Sep 20, 2026
Ruby master branch (ruby 4.1.0dev) now warns when `alias` in a module
falls back to `Object`. The plan is to raise `NameError` in Ruby 4.3.

https://bugs.ruby-lang.org/issues/22276
ruby/ruby#18740

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Oct 12, 2026
Ruby master branch (ruby 4.1.0dev) now warns when `alias` in a module
falls back to `Object`. The plan is to raise `NameError` in Ruby 4.3.

https://bugs.ruby-lang.org/issues/22276
ruby/ruby#18740

This is the same approach as rails#56705 for `read_attribute_for_serialization`,
extracted from rails#56130 without its behavior change.

Co-authored-by: Lovro Bikic <lovro.bikic@infinum.hr>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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