Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

super inside def self.new behaves incorrect when called via alias #927

Closed
mbj opened this issue Jul 29, 2013 · 3 comments
Closed

super inside def self.new behaves incorrect when called via alias #927

mbj opened this issue Jul 29, 2013 · 3 comments
Milestone

Comments

@mbj
Copy link

mbj commented Jul 29, 2013

When defining new on a class singleton that gets aliased to another name, super inside the class dispatches to the aliased, not the original name. MRI and RBX both behave different here and dispatch to superclasses original named method.

crash.rb

class Foo

  def self.new
    super
  end

  class << self
    alias_method :bar, :new
  end

end

p Foo.bar

jruby:

jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM 1.7.0_40-b31 +indy [linux-am

mbj@mbj ~/devel/crash (master*) % jruby crash.rb
NoMethodError: super: no superclass method `bar'
     new at crash.rb:4
  (root) at crash.rb:13

cruby:

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

mbj@mbj ~/devel/crash (master*) % ruby crash.rb
#<Foo:0x007f0f1d4fc580>

I reduced this bug from around 20kloc, and hope you can fix it in the next minor release. I can trigger this very easily from my production code. Using 1.7.2 now where this bug does not exist.

@mbj
Copy link
Author

mbj commented Jul 30, 2013

Update, turns out that using interpreted mode -X-C makes this bug disappear.

@mbj
Copy link
Author

mbj commented Jul 30, 2013

Here is my full java -version

java version "1.7.0_40"
OpenJDK Runtime Environment (IcedTea 2.4.1) (ArchLinux build 7.u40_2.4.1-1-x86_64)
OpenJDK 64-Bit Server VM (build 24.0-b50, mixed mod

@BanzaiMan
Copy link
Member

I believe this is fixed on master.

$ jruby -v crash.rb 
jruby 1.7.5.dev (1.9.3p392) 2013-08-19 362730c on Java HotSpot(TM) 64-Bit Server VM 1.7.0_25-b15 [darwin-x86_64]
#<Foo:0x5b470886>

You can trying a package from http://ci.jruby.org/snapshots/master/ or building it yourself.

I'm closing this now, but let me know if it's still a problem for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants