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

cloned singleton method exists but can't be overwritten #4229

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

cloned singleton method exists but can't be overwritten #4229

eprothro opened this issue Oct 14, 2016 · 2 comments

Comments

@eprothro
Copy link

@eprothro eprothro commented Oct 14, 2016

Likely the same root cause as #4228

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

A singleton method that is cloned and then redefined is overwritten, not overridden.

MRI

class Foo
  def bar
    puts 'class method'
  end
end

object = Foo.new
object.define_singleton_method(:bar) do
  puts 'instance method 1'
  super()
end

cloned = object.clone
cloned.define_singleton_method(:bar) do
  puts 'instance method 2'
  super()
end
cloned.bar
#=> instance method 2
#=> class method

Actual Behavior

class Foo
  def bar
    puts 'class method'
  end
end

object = Foo.new
object.define_singleton_method(:bar) do
  puts 'instance method 1'
  super()
end

cloned = object.clone
cloned.define_singleton_method(:bar) do
  puts 'instance method 2'
  super()
end
cloned.bar
#=> instance method 2
#=> instance method 1
#=> class method
@headius
Copy link
Member

@headius headius commented Oct 18, 2016

Looks like we're not properly cloning the singleton class...probably using the old one as superclass for the new clone.

@headius
Copy link
Member

@headius headius commented Oct 18, 2016

I created #4233 to test my changes. Your test case passes and I turned it into a spec for ruby/spec. We'll see how it looks in CI.

@headius headius added this to the JRuby 1.7.27 milestone Oct 18, 2016
@headius headius modified the milestones: JRuby 9.1.6.0, JRuby 1.7.27 Oct 18, 2016
headius added a commit to headius/jruby that referenced this issue Nov 8, 2016
@headius headius closed this in afe5e51 Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.