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

Kernel#__method__ within a proc returns incorrect value after method definition #2212

Closed
gdeoliveira opened this Issue Nov 17, 2014 · 5 comments

Comments

Projects
None yet
3 participants
@gdeoliveira
Copy link

gdeoliveira commented Nov 17, 2014

When defining more than one method within a class using a proc that returns __method__ all methods will return the symbol representing the last defined method:

DEFINITION = proc { __method__ }

class C
  define_method :one, DEFINITION
  define_method :two, DEFINITION
end

o = C.new

puts o.one  #=> :two (in MRI this returns :one)
puts o.two  #=> :two

Casting DEFINITION into a code block during the method's definition seems to be working correctly though:

class C
  define_method :one, &DEFINITION
  define_method :two, &DEFINITION
end

o = C.new

puts o.one  #=> :one
puts o.two  #=> :two

A lengthier description of the problem can be found at this post in Stack Overflow.

gdeoliveira added a commit to gdeoliveira/mabbre that referenced this issue Nov 17, 2014

@kares

This comment has been minimized.

Copy link
Member

kares commented Jun 11, 2018

working as expected in JRuby 9.1.16 (and likely earlier releases as well) :

jruby-9.1.16.0 :046 > DEFINITION = proc { __method__ }
 => #<Proc:0xd23e042@(irb):46> 
jruby-9.1.16.0 :047 > 
jruby-9.1.16.0 :048 >   class C
jruby-9.1.16.0 :049?>     define_method :one, DEFINITION
jruby-9.1.16.0 :050?>     define_method :two, DEFINITION
jruby-9.1.16.0 :051?>   end
 => :two 
jruby-9.1.16.0 :052 > 
jruby-9.1.16.0 :053 >   o = C.new
 => #<C:0x66ea810> 
jruby-9.1.16.0 :054 > puts o.one 
two
 => nil 
jruby-9.1.16.0 :055 > puts o.two
two
 => nil 

@kares kares closed this Jun 11, 2018

@kares kares added this to the Invalid or Duplicate milestone Jun 11, 2018

@gdeoliveira

This comment has been minimized.

Copy link
Author

gdeoliveira commented Jun 11, 2018

@kares, I believe this is still working incorrectly, as the following should print "one" instead to match MRI's behaviour:

jruby-9.1.16.0 :054 > puts o.one 
two
 => nil
@kares

This comment has been minimized.

Copy link
Member

kares commented Jun 11, 2018

@gdeoliveira right, have misread what is expected and what is JRuby behavior ... let's have it open than

@kares kares reopened this Jun 11, 2018

@kares kares removed this from the Invalid or Duplicate milestone Jun 11, 2018

@headius

This comment has been minimized.

Copy link
Member

headius commented Jun 11, 2018

Likely an issue with how the define_method methods share frames. However I'd have expected them to have their own names for super at least.

headius added a commit to headius/jruby that referenced this issue Jun 11, 2018

@headius headius added this to the JRuby 9.2.1.0 milestone Jun 11, 2018

@headius headius added the core label Jun 11, 2018

@headius

This comment has been minimized.

Copy link
Member

headius commented Jun 11, 2018

I pushed a PR that fixes this. Needs specs for the given case and for super inside a similar case as noted in #5214. @gdeoliveira Perhaps you'd like to try your hand at contributing to https://github.com/ruby/spec?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.