# Bug in Kernel#method objects that call super?

**URL:** <https://www.ruby-forum.com/t/bug-in-kernel-method-objects-that-call-super/108932>\
**Category:** Ruby\
**Created:** [July 9, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/bug-in-kernel-method-objects-that-call-super/108932 "2007-07-09T17:32:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![headius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7c8e57/32.png) [@headius](https://www.ruby-forum.com/u/headius)\
**Post date:** [July 9, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/bug-in-kernel-method-objects-that-call-super/108932/1 "2007-07-09T17:32:21Z")

</div>

I posted this to ruby-core and got a somewhat mixed response. I’m  
curious what the rest of you might think of this behavior.

-------- Original Message --------  
Subject: Bug in Kernel#method objects that call super?  
Date: Sat, 07 Jul 2007 05:57:13 +0900  
From: Charles Oliver N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Reply-To: removed\_email\_address@domain.invalid  
To: removed\_email\_address@domain.invalid

This seems very wrong to me. Calling through a method object should  
behave the same for super as calling directly or calling through an  
alias:

class Foo  
def a; puts ‘Foo a’; end  
def b; puts ‘Foo b’; end  
end

class Bar \< Foo  
def a; puts ‘Bar a’; super; end  
alias b a  
end

Bar.new.a # =\> “Bar a\nFoo a”  
Bar.new.b # =\> “Bar a\nFoo a”  
Bar.new.method(:b).call # =\> “Bar a\nFoo b”

It seems incorrect for method objects to change the behavior of super.  
If I super in ‘a’, I want super’s ‘a’ to be called, without exception.

Can someone confirm this is a bug? In JRuby we always super up the  
same-named chain, so this represents an incompatibility.

- Charlie

---

<div class="post-metadata">

**Author:** ![headius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7c8e57/32.png) [@headius](https://www.ruby-forum.com/u/headius)\
**Post date:** [July 9, 2007, 10:46pm UTC](https://www.ruby-forum.com/t/bug-in-kernel-method-objects-that-call-super/108932/2 "2007-07-09T22:46:53Z")

</div>

HI –

On Tue, 10 Jul 2007, Charles Oliver N. wrote:

> def a; puts ‘Bar a’; super; end  
> alias b a  
> end
> 
> Bar.new.a # =\> “Bar a\nFoo a”  
> Bar.new.b # =\> “Bar a\nFoo a”  
> Bar.new.method(:b).call # =\> “Bar a\nFoo b”
> 
> It seems incorrect for method objects to change the behavior of super.  
> If I super in ‘a’, I want super’s ‘a’ to be called, without exception.

I agree that it’s very odd that the two ways of calling behave  
differently. A secondary question is whether the #method behavior –  
the dynamic calculation of what method super should look for – has  
any useful application. I can’t think of any. Maybe we need “super!”  
🙂

David

---

<div class="post-metadata">

**Author:** ![headius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7c8e57/32.png) [@headius](https://www.ruby-forum.com/u/headius)\
**Post date:** [July 9, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/bug-in-kernel-method-objects-that-call-super/108932/3 "2007-07-09T23:35:58Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I agree that it’s very odd that the two ways of calling behave  
> differently. A secondary question is whether the #method behavior –  
> the dynamic calculation of what method super should look for – has  
> any useful application. I can’t think of any. Maybe we need “super!”  
> 🙂

I can’t really think of any either; if you want that sort of  
polymorphism on a superclass, you shouldn’t use super.

- Charlie

---

<div class="post-metadata">

**Author:** ![headius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7c8e57/32.png) [@headius](https://www.ruby-forum.com/u/headius)\
**Post date:** [July 10, 2007, 4:25am UTC](https://www.ruby-forum.com/t/bug-in-kernel-method-objects-that-call-super/108932/4 "2007-07-10T04:25:21Z")

</div>

On 7/9/07, Charles Oliver N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This seems very wrong to me. Calling through a method object should  
> alias b a  
> Can someone confirm this is a bug? In JRuby we always super up the  
> same-named chain, so this represents an incompatibility.

I think the bug is in alias and not in #method …

Or at least the bug is brought about by some odd interaction between  
alias and #method. My WAG at the problem is that alias creates a copy  
of the method :a and renames it method :b in Bar. There is some hint  
in the lookup table in class Bar that tells the Ruby interpreter –  
“hey, this is really method :a, so super should redirect to method :a  
in the superclass”.

When #method generates the Proc object, this hinting is not preserved.  
So, when super is called, it redirects to method :b in Foo.

Again, just my WAG – I have not looked at the source code on this one.

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![headius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7c8e57/32.png) [@headius](https://www.ruby-forum.com/u/headius)\
**Post date:** [July 10, 2007, 3:05am UTC](https://www.ruby-forum.com/t/bug-in-kernel-method-objects-that-call-super/108932/5 "2007-07-10T03:05:15Z")

</div>

On Jul 9, 2007, at 9:31 AM, Charles Oliver N. wrote:

> This seems very wrong to me

me too.

-a
