Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not override Kernel#warn when there is no need #4075

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rubygems.rb
Expand Up @@ -119,6 +119,10 @@ module Gem
# to avoid deprecation warnings in Ruby 2.7.
UNTAINT = RUBY_VERSION < '2.7' ? :untaint.to_sym : proc{}

# When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn
KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" ||
deivid-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
(RUBY_ENGINE == "ruby" && RUBY_VERSION >= '3.0')

##
# An Array of Regexps that match windows Ruby platforms.

Expand Down
3 changes: 3 additions & 0 deletions lib/rubygems/core_ext/kernel_require.rb
Expand Up @@ -17,6 +17,8 @@ module Kernel
private :gem_original_require
end

file = Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES ? "<internal:#{__FILE__}>" : __FILE__
module_eval <<'RUBY', file, __LINE__ + 1
deivid-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
##
# When RubyGems is required, Kernel#require is replaced with our own which
# is capable of loading gems on demand.
Expand Down Expand Up @@ -166,6 +168,7 @@ def require(path)
end
end
end
RUBY

private :require

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/core_ext/kernel_warn.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# `uplevel` keyword argument of Kernel#warn is available since ruby 2.5.
if RUBY_VERSION >= "2.5"
if RUBY_VERSION >= "2.5" && !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES
eregon marked this conversation as resolved.
Show resolved Hide resolved

module Kernel
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path.
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_require.rb
Expand Up @@ -709,7 +709,7 @@ def deprecated
RUBY

_, err = capture_subprocess_io do
system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb")
system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb")
end
assert_match(/main\.rb:2: warning: This is a deprecated method$/, err)
_, err = capture_subprocess_io do
Expand Down