[ruby-core:22040] [Bug #1151] Aliased methods change super logic when retrieved with Object#method

View: New views
6 Messages — Rating Filter:   Alert me  

[ruby-core:22040] [Bug #1151] Aliased methods change super logic when retrieved with Object#method

by Dominik Elsbroek-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bug #1151: Aliased methods change super logic when retrieved with Object#method
http://redmine.ruby-lang.org/issues/show/1151

Author: Charles Nutter
Status: Open, Priority: Normal
ruby -v: 1.8.6 (all versions) and 1.8.7

This is a peculiar case I don't believe I've reported before. It seems that "method" can change the super behavior of an alias:

 # Test weird likely-a-bug where method() will repurpose where super goes to
 class Foo222
   def a; 'a'; end
   def b; 'b'; end
 end
 
 class Bar222 < Foo222
   def a; super; end
   alias b a
 end
 
 puts('a' == Bar222.new.b) # true
 puts('a' == Bar222.new.method(:b).call) # false

Ruby 1.9 behaves as you would expect, calling the "a" super method in both cases. We changed our behavior in JRuby 1.1.2 to match Ruby 1.8.6, but I still believe this is a bug. The JRuby bug report is here: http://jira.codehaus.org/browse/JRUBY-1192 and I reported it to ruby-core here: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/11600 and a patch was proposed here: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/11603. Since it behaves as I expect in 1.9, I assume the 1.8.x behavior is incorrect.


----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:23003] [Bug #1151] Aliased methods change super logic when retrieved with Object#method

by Dominik Elsbroek-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1151 has been updated by Charles Nutter.


Any comments on this one? I've run into another case where I could fix this and improve other JRuby behavior, but I need confirmation that the Ruby 1.8 behavior is incorrect.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1151

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:23004] [Bug #1151] Aliased methods change super logic when retrieved with Object#method

by Dominik Elsbroek-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1151 has been updated by Charles Nutter.


A bit more background...

I am adding inline caching to super calls. The "buggy" behavior makes this more complicated, since depending on whether the "a" child method or "b" alias was called, the super path will be different, even though the call site is the same and the method containing it is the same.

I am temporarily adding logic to my cache that will check if the name has changed, but I still find this behavior counter-intuitive, and I believe it is a bug.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1151

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:26437] [Bug #1151] Aliased methods change super logic when retrieved with Object#method

by Dominik Elsbroek-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1151 has been updated by Matt Jones.


Not sure if this is related or not, but I've run across another very similar issue regarding method(:name).call not being equivalent to calling the method.

Example is here: http://gist.github.com/221585

The net result is more dramatic than in this example; rather than simply calling the wrong method, the call to super fails with 'superclass not found'. But the essential problem is the same - calling B.new.foo produces a different result than B.new.method(:foo).call.

@Charles - can you try the Gist out on JRuby? Thanks!
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1151

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:26486] Re: [Bug #1151] Aliased methods change super logic when retrieved with Object#method

by Charles Oliver Nutter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 30, 2009 at 9:53 AM, Matt Jones <redmine@...> wrote:
> Not sure if this is related or not, but I've run across another very similar issue regarding method(:name).call not being equivalent to calling the method.
>
> Example is here: http://gist.github.com/221585
>
> The net result is more dramatic than in this example; rather than simply calling the wrong method, the call to super fails with 'superclass not found'. But the essential problem is the same - calling B.new.foo produces a different result than B.new.method(:foo).call.

In JRuby, it produces the expected output in both cases:

~/projects/jruby ➔ jruby foo.rb
Overridden foo
Overridden foo

(or at least, I believe this is the behavior you would expect to see)

Ruby versions all seem to do it differently, with only 1.8.6 matching
JRuby's output:

~/projects/jruby ➔ ruby foo.rb
Overridden foo
Overridden foo

~/projects/jruby ➔ ruby1.8.7 foo.rb
Overridden foo
foo.rb:5:in `foo': super: no superclass method `foo' (NoMethodError)
        from foo.rb:28:in `call'
        from foo.rb:28

~/projects/jruby ➔ ruby1.9 foo.rb
module foo
module foo

The odd results don't make sense to me.

- Charlie


[ruby-core:26629] [Bug #1151](Closed) Aliased methods change super logic when retrieved with Object#method

by Dominik Elsbroek-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1151 has been updated by Marc-Andre Lafortune.

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

This issue was solved with changeset r25693.
Charles, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

----------------------------------------
http://redmine.ruby-lang.org/issues/show/1151

----------------------------------------
http://redmine.ruby-lang.org