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

warning: method redefined; discarding old require #461

Closed
MaxLap opened this issue Dec 13, 2023 · 2 comments · Fixed by #462
Closed

warning: method redefined; discarding old require #461

MaxLap opened this issue Dec 13, 2023 · 2 comments · Fixed by #462

Comments

@MaxLap
Copy link

MaxLap commented Dec 13, 2023

Running a rake test task with verbose set to true, outputs the warning ".../ruby-3.2.2@nagano3/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:8: warning: method redefined; discarding old require"

Here is an example of such a setting

  Rake::TestTask.new(:quick_check) do |t|
    # ...
    t.verbose = true
  end

Launching a Rails console with RUBYOPT=-w also has the same warning.

I guess there could be race conditions if you first #undef the method. I wonder if you could turn this into a module that is #prepend to Kernel?

Bootsnap version: 1.17.0

Ruby version: 3.2.2

Rails version: 7.0.8

@byroot
Copy link
Contributor

byroot commented Dec 13, 2023

I wonder if you could turn this into a module that is #prepend to Kernel?

No it's not possible because rubygems uses a similar alias_method chain, and it doesn't mix well with prepend. Zeitwerk also alias method chain require, so we'd need to coordinate all this which is practically not possible.

In the meantime I can silence that warning using the alias_method trick:

module Kernel
  module_function

  alias_method :require, :require
  class << self
    alias_method :require, :require
  end

  def require(path)
  end
end

It's just weird I never noticed that warning before.

@MaxLap
Copy link
Author

MaxLap commented Dec 13, 2023

Understood, thanks for taking the time to explain!

casperisfine pushed a commit that referenced this issue Dec 14, 2023
Fix: #461

Also neither Rubygems nor Zeitwerk bother decorating
`Kernel.require`, and no-one requires with `Kernel.require` so
likely not worth it, and if anything that offers an escape hatch to
bypass Bootsnap.
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 a pull request may close this issue.

2 participants