Project

General

Profile

Actions

Bug #22273

open

Aliasing doesn't interact well with Module#prepend

Bug #22273: Aliasing doesn't interact well with Module#prepend

Added by luke-gru (Luke Gruber) about 6 hours ago. Updated about 4 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:126530]

Description

Currently, aliasing doesn't interact well with Module#prepend in my opinion.

Example

module Kernel
  prepend(Module.new do
    def require(feature)
      puts "requiring feature (prepend): #{feature}"
      super
    end
  end)
end

module Kernel
  alias original_require require
  def require(feature)
    puts "requiring feature (alias): #{feature}"
    original_require(feature)
  end
end

require "set"

This produces this behavior:

requiring feature (prepend): set
requiring feature (alias): set
requiring feature (prepend): set
../ruby/test.rb:5:in 'require': super: no superclass method 'require' for main (NoMethodError)

I would expect this behavior:

requiring feature (prepend): set
requiring feature (alias): set
# Then, the original require would succeed

This has caused issues such as 22263 and has confused gem authors. In the second link, the ignored alias was due to this bug which has recently been fixed.

Bug?

As far as I know this is intentional behavior introduced in Ruby 2.0 here. There are even tests and specs that codify this behavior such as test_prepend_super_in_alias and prepend_spec.rb.

Even though it's intentional, I don't believe it's well thought out. I'm interested in hearing arguments for and against the current behavior (with code examples, preferably).


Related issues 2 (1 open1 closed)

Related to Ruby - Bug #7842: An alias of a "prepend"ed method skips the original method when calling superClosednobu (Nobuyoshi Nakada)Actions
Related to Ruby - Bug #22263: NoMethodError: super: no superclass method 'require' for main — raised in a forked child process after a Ractor has exited in the parent (bisected to c59c4d717a)OpenActions

Updated by jhawthorn (John Hawthorn) about 6 hours ago Actions #1

  • Related to Bug #7842: An alias of a "prepend"ed method skips the original method when calling super added

Updated by jhawthorn (John Hawthorn) about 6 hours ago Actions #2

  • Related to Bug #22263: NoMethodError: super: no superclass method 'require' for main — raised in a forked child process after a Ractor has exited in the parent (bisected to c59c4d717a) added

Updated by luke-gru (Luke Gruber) about 4 hours ago Actions #3

  • Description updated (diff)
Actions

Also available in: PDF Atom