Project

General

Profile

Actions

Bug #16736

closed

Prepending blank module breaks super call in aliased method

Added by tycooon (Yuri Smirnov) about 4 years ago. Updated almost 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
[ruby-core:97581]

Description

Here is the test script:

class A
  def key
    ["some_key"]
  end
end

module M
  prepend Module.new

  def self.included(base)
    base.alias_method :base_key, :key
  end

  def key
    super + ["new_key"]
  end

  def generate
    base_key
  end
end

class B < A
  include M
end

x = B.new
p x.generate

In Ruby 2.7 I get the following error:

Traceback (most recent call last):
	2: from test.rb:28:in `<main>'
	1: from test.rb:19:in `generate'
test.rb:15:in `key': super: no superclass method `key' for #<B:0x00007fbc1704d028> (NoMethodError)

If I remove the prepend Module.new line or switch to Ruby 2.6, I get the expected result:

["some_key", "new_key"]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0