Bug #918

super doesn't work correctly when used with define_method

Added by Tomas Matousek over 6 years ago. Updated about 4 years ago.

[ruby-core:20786]
Status:Closed
Priority:Normal
Assignee:-
ruby -v: Backport:

Description

=begin
The following prints B,A in 1.8 but B,B,A in 1.9.*.
It seems that the receiver's class (C) is incorrectly used to determine the base class. The class where the target method (B#m) is defined (i.e. B) should be used so that A#m is invoked immediately.

class A
def m
puts 'A'
end
end

class B < A
define_method(:m) do

puts 'B'
super()
end
end

class C < B
end

C.new.m
=end

History

#1 Updated by Michael Klishin over 6 years ago

=begin
Tomas,

I think the same problem has been reported in #730. Could you check if they are duplicates? Thanks.
=end

#2 Updated by Koichi Sasada over 6 years ago

=begin
Tomas Matousek wrote::

The following prints B,A in 1.8 but B,B,A in 1.9.*.
It seems that the receiver's class (C) is incorrectly used to determine the base class. The class where the target method (B#m) is defined (i.e. B) should be used so that A#m is invoked immediately.

On my environment, following patch fixes this issue. Could you try it?
http://www.atdot.net/sp/readonly/ildack

--
// SASADA Koichi at atdot dot net

=end

#3 Updated by Tomas Matousek over 6 years ago

=begin
It might be related yet there might also be an issue specific to define_method. It depends on implementation details in Ruby.
=end

#4 Updated by Tomas Matousek over 6 years ago

=begin
Thanks for fixing this so quickly. Unfortunately I can't work with Ruby source code. I would need Win32 binaries to test it.
=end

#5 Updated by Michael Klishin over 6 years ago

=begin
ko1,

Your patch fixes the problem, though does not help with #730.

I ran test-all as well as test-rubyspec against patched 1.9.1 from today.

=end

#6 Updated by Koichi Sasada over 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r20967.
=end

Also available in: Atom PDF