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

alias method doesn't work as expected #5291

Open
jankowy opened this Issue Aug 27, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@jankowy

jankowy commented Aug 27, 2018

Environment

  • JRuby version
    jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.181-b13 on 1.8.0_181-8u181-b13-1~deb9u1-b13 +jit [linux-x86_64]
  • Operating system and platform
    Linux b8eda5147dd5 4.15.0-33-generic #36-Ubuntu SMP Wed Aug 15 16:00:05 UTC 2018 x86_64 GNU/Linux

I have two simple ruby scripts:

# alias.rb

class User

  def full_name
    puts "Johnnie Walker"
  end

  def self.add_rename
    alias name full_name
  end
end

class Developer < User
  def full_name
    puts "Geeky geek"
  end
  add_rename
end

Developer.new.name #=> Johnnie Walker"

and

# alias_method.rb

class User

  def full_name
    puts "Johnnie Walker"
  end

  def self.add_rename
    alias_method :name, :full_name
  end
end

class Developer < User
  def full_name
    puts "Geeky geek"
  end
  add_rename
end

Developer.new.name #=> "Geeky geek"

Expected Behavior

On CRuby everything works as excpeted:

root@ed81cc48a8a7:/app# ruby alias.rb 
Johnnie Walker
root@ed81cc48a8a7:/app# ruby alias_method.rb 
Geeky geek
root@ed81cc48a8a7:/app# ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

Actual Behavior

On JRuby alias and alias_method seem to work the same way:

root@b8eda5147dd5:/app# ruby --version
jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.181-b13 on 1.8.0_181-8u181-b13-1~deb9u1-b13 +jit [linux-x86_64]
root@b8eda5147dd5:/app# ruby alias.rb 
Geeky geek
root@b8eda5147dd5:/app# ruby alias_method.rb 
Geeky geek

@enebo enebo added this to the JRuby 9.2.1.0 milestone Aug 27, 2018

@ChrisBr

This comment has been minimized.

Show comment
Hide comment
@ChrisBr

ChrisBr Aug 27, 2018

Contributor

Confirmed on current master, first glance looks like we only have one method cache for alias and alias_method...

Contributor

ChrisBr commented Aug 27, 2018

Confirmed on current master, first glance looks like we only have one method cache for alias and alias_method...

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Aug 27, 2018

Member

I'd guess that "alias" within a self.whatever (defs) style method is not getting the proper location to define its new target, or is otherwise just using the wrong target.

I do wonder if this behavioral difference between alias and alias_method is intentional though. Perhaps this should be raised with ruby-core for clarification?

Member

headius commented Aug 27, 2018

I'd guess that "alias" within a self.whatever (defs) style method is not getting the proper location to define its new target, or is otherwise just using the wrong target.

I do wonder if this behavioral difference between alias and alias_method is intentional though. Perhaps this should be raised with ruby-core for clarification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment