Skip to content

Autoload RubyGems internals by feature name - #9830

Open
hsbt wants to merge 2 commits into
masterfrom
claude/name-tuple-redefinition-warnings-c0306b
Open

Autoload RubyGems internals by feature name#9830
hsbt wants to merge 2 commits into
masterfrom
claude/name-tuple-redefinition-warnings-c0306b

Conversation

@hsbt

@hsbt hsbt commented Aug 31, 2026

Copy link
Copy Markdown
Member

Gem autoloads its own constants by absolute path, and an absolute path skips the $LOADED_FEATURES check. When a second RubyGems tree sits on the load path, the copy that is still loading pulls the other one in through that autoload, and every method it defines gets redefined on top of it.

Running exe/bundle from a checkout triggers this now that lib holds RubyGems and Bundler side by side. Under RUBYOPT=-w a single bundle --version prints 175 redefinition warnings, 14 of them from name_tuple.rb. Autoloading by feature name takes the same lookup an ordinary require does, so only one copy is loaded.

The test starts a child with a second copy of rubygems/name_tuple.rb ahead of the real one and asserts that $LOADED_FEATURES holds exactly one.

hsbt and others added 2 commits August 31, 2026 14:37
An absolute path skips the `$LOADED_FEATURES` check, so a second RubyGems tree on the load path gets loaded on top of the one already loading and redefines every method in it. A checkout hits this through `exe/bundle`, which puts its `lib` first and now ships RubyGems next to Bundler there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This is the last autoload left holding an absolute path. Nothing loads a second copy of it today, but it carries the same hazard as the ones in `rubygems.rb`.

Co-Authored-By: Claude Opus 5 <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