remove_method fails to remove singleton method on cloned object #4228

Closed
eprothro opened this Issue Oct 14, 2016 · 2 comments

Projects

None yet

2 participants

@eprothro
eprothro commented Oct 14, 2016 edited

Environment

  • jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 25.72-b15 on 1.8.0_72-b15 +jit [darwin-x86_64]
  • Darwin Evans-2015-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64

Expected Behavior

MRI

class Foo
  def bar
    puts "*** class method"
  end
end

object = Foo.new

object.define_singleton_method "bar" do
  puts "*** singleton method"
end

cloned = object.clone

cloned.singleton_methods
#=> bar

if cloned.singleton_methods.include?(:bar)
  cloned.singleton_class.class_eval do
    remove_method :bar
  end
end

cloned.bar
#=> *** class method

Actual Behavior

class Foo
  def bar
    puts "*** class method"
  end
end

object = Foo.new

object.define_singleton_method "bar" do
  puts "*** singleton method"
end

cloned = object.clone

cloned.singleton_methods
#=> bar

if cloned.singleton_methods.include?(:bar)
  cloned.singleton_class.class_eval do
    remove_method :bar
  end
end
NameError: method 'bar' not defined in #<Class:0x45752059>
    from org/jruby/RubyModule.java:2882:in `remove_method'
    from (irb):20:in `block in evaluate'
    from org/jruby/RubyModule.java:2832:in `module_eval'
    from (irb):19:in `<eval>'
    from org/jruby/RubyKernel.java:995:in `eval'
    from org/jruby/RubyKernel.java:1296:in `loop'
    from org/jruby/RubyKernel.java:1115:in `catch'
    from org/jruby/RubyKernel.java:1115:in `catch'
    from /Users/eprothro/.rbenv/versions/jruby-9.1.5.0/bin/irb:13:in `<main>'
@headius
Member
headius commented Oct 18, 2016

This appears to be fixed by #4233. I'll add another spec to that PR for this issue.

@headius headius added this to the JRuby 9.1.6.0 milestone Oct 18, 2016
@headius headius added a commit to headius/jruby that referenced this issue Oct 18, 2016
@headius headius Add spec for remove_method against cloned singleton. 8312db6
@headius headius added a commit to headius/jruby that referenced this issue Nov 8, 2016
@headius headius Add spec for remove_method against cloned singleton. d909f04
@headius
Member
headius commented Nov 8, 2016

Fixed by #4233. Specs in that PR.

@headius headius closed this Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment