Skip to content

Fix incorrect bundled gems warning for hyphenated gem names - #15822

Merged
hsbt merged 1 commit into
ruby:masterfrom
khasinski:fix-bundled-gems-hyphenated-warning
Jan 8, 2026
Merged

Fix incorrect bundled gems warning for hyphenated gem names#15822
hsbt merged 1 commit into
ruby:masterfrom
khasinski:fix-bundled-gems-hyphenated-warning

Conversation

@khasinski

@khasinski khasinski commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes https://bugs.ruby-lang.org/issues/21828 - incorrect warning when using gems with hyphenated names like benchmark-ips.

Problem

When requiring "benchmark/ips" (from the benchmark-ips gem), Ruby 4.0 incorrectly warns:

benchmark/ips is found in benchmark, which is not part of the default gems since Ruby 4.0.0.
You can add benchmark to your Gemfile or gemspec to fix this error.

This is misleading because benchmark-ips is a completely separate third-party gem, not part of the benchmark standard library.

The warning logic splits the require path by / and checks if the first segment (benchmark) is a removed default gem. It doesn't account for the Ruby convention where a gem named foo-bar provides foo/bar as its require path.

Solution

Before warning, check if a hyphenated version of the require path exists in the bundle specs:

  # "benchmark/ips" → checks for "benchmark-ips" in Gemfile
  hyphenated_gem = "#{feature_parts[0]}-#{feature_parts[1]}"
  return if specs.include?(hyphenated_gem)

When requiring a file like "benchmark/ips", the warning system would
incorrectly warn about the "benchmark" gem not being a default gem,
even when the user has "benchmark-ips" (a separate third-party gem)
in their Gemfile.

The fix checks if a hyphenated version of the require path exists in
the bundle specs before issuing a warning. For example, requiring
"benchmark/ips" now checks for both "benchmark" and "benchmark-ips"
in the Gemfile.

[Bug #21828]

@hsbt hsbt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@hsbt
hsbt merged commit 7688628 into ruby:master Jan 8, 2026
92 checks passed
@khasinski
khasinski deleted the fix-bundled-gems-hyphenated-warning branch January 8, 2026 09:34
khasinski added a commit to khasinski/ruby that referenced this pull request Jan 19, 2026
PR ruby#15822 fixed the warning for direct hyphenated gem requires like
`benchmark/ips` → `benchmark-ips`. However, hyphenated gems often
provide multiple files under their namespace.

For example, `benchmark-ips` provides:
- benchmark/ips.rb
- benchmark/timing.rb
- benchmark/compare.rb

When requiring `benchmark/timing`, the previous fix only checked for
`benchmark-timing` gem (doesn't exist), not `benchmark-ips` which
actually provides the file.

This fix checks if ANY gem matching `{prefix}-*` is in the bundle
specs, which covers all subfeatures provided by hyphenated gems.

Reported in ruby#15822 (comment)
hsbt pushed a commit that referenced this pull request Feb 12, 2026
PR #15822 fixed the warning for direct hyphenated gem requires like
`benchmark/ips` → `benchmark-ips`. However, hyphenated gems often
provide multiple files under their namespace.

For example, `benchmark-ips` provides:
- benchmark/ips.rb
- benchmark/timing.rb
- benchmark/compare.rb

When requiring `benchmark/timing`, the previous fix only checked for
`benchmark-timing` gem (doesn't exist), not `benchmark-ips` which
actually provides the file.

This fix checks if ANY gem matching `{prefix}-*` is in the bundle
specs, which covers all subfeatures provided by hyphenated gems.

Reported in #15822 (comment)
hsbt pushed a commit to hsbt/ruby that referenced this pull request Feb 12, 2026
PR ruby#15822 fixed the warning for direct hyphenated gem requires like
`benchmark/ips` → `benchmark-ips`. However, hyphenated gems often
provide multiple files under their namespace.

For example, `benchmark-ips` provides:
- benchmark/ips.rb
- benchmark/timing.rb
- benchmark/compare.rb

When requiring `benchmark/timing`, the previous fix only checked for
`benchmark-timing` gem (doesn't exist), not `benchmark-ips` which
actually provides the file.

This fix checks if ANY gem matching `{prefix}-*` is in the bundle
specs, which covers all subfeatures provided by hyphenated gems.

Reported in ruby#15822 (comment)
k0kubun pushed a commit that referenced this pull request Feb 12, 2026
PR #15822 fixed the warning for direct hyphenated gem requires like
`benchmark/ips` → `benchmark-ips`. However, hyphenated gems often
provide multiple files under their namespace.

For example, `benchmark-ips` provides:
- benchmark/ips.rb
- benchmark/timing.rb
- benchmark/compare.rb

When requiring `benchmark/timing`, the previous fix only checked for
`benchmark-timing` gem (doesn't exist), not `benchmark-ips` which
actually provides the file.

This fix checks if ANY gem matching `{prefix}-*` is in the bundle
specs, which covers all subfeatures provided by hyphenated gems.

Reported in #15822 (comment)
paracycle pushed a commit to Shopify/ruby that referenced this pull request Feb 15, 2026
PR ruby#15822 fixed the warning for direct hyphenated gem requires like
`benchmark/ips` → `benchmark-ips`. However, hyphenated gems often
provide multiple files under their namespace.

For example, `benchmark-ips` provides:
- benchmark/ips.rb
- benchmark/timing.rb
- benchmark/compare.rb

When requiring `benchmark/timing`, the previous fix only checked for
`benchmark-timing` gem (doesn't exist), not `benchmark-ips` which
actually provides the file.

This fix checks if ANY gem matching `{prefix}-*` is in the bundle
specs, which covers all subfeatures provided by hyphenated gems.

Reported in ruby#15822 (comment)
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