Project

General

Profile

Actions

Bug #2420

closed

super call may use wrong receiver object

Added by nobu (Nobuyoshi Nakada) about 15 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2dev (2009-12-01 trunk 25970) [i386-darwin9.0]
Backport:
[ruby-core:27000]

Description

=begin
The code below prints:
C
main
Object::m

which means that the super calls the instance method B#m on a receiver that is not an instance of B. It's not what makes the super call to pick the main object as a receiver in this case. I would expect it to use the "self" object that the block captures, i.e. the class object C, and thus an exception "no superclass method `m' (NoMethodError)" should be raised.

class B
def m
p self
puts self.class.to_s + '::m'
end
end

class C < B
q = Proc.new do
p self
super()
end

mq = define_method :m, &q

mq.call
end

BTW: The behavior is even worse in Ruby 1.9:
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]
C
a.rb:11:in ==': wrong number of arguments(0 for 1) (ArgumentError) from a.rb:11:in block in class:C'
from a.rb:16:in call' from a.rb:16:in class:C'
from a.rb:8:in `'
=end


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #3136: reuse of singleton method definition causes SEGVClosedko1 (Koichi Sasada)04/12/2010Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0