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

Set#dup does not seem to call #initialize_copy #6903

Closed
postmodern opened this issue Oct 22, 2021 · 5 comments
Closed

Set#dup does not seem to call #initialize_copy #6903

postmodern opened this issue Oct 22, 2021 · 5 comments

Comments

@postmodern
Copy link

postmodern commented Oct 22, 2021

I ran into this edge-case when working with classes which inherit from Set (I know, I probably shouldn't do that) and the classes contain other instance variables which require custom initialize_copy logic to copy them over when the set is duplicated, such as when Set#| is called; the implementation of Set#| on both CRuby and JRuby is essentially dup.merge(other).

Under JRuby (9.3.1.0), the custom initialize_copy method does not seem to be called when Set#dup is called.

Steps To Reproduce

require 'set'

class FooObject
  def initialize_copy(other)
    puts "#{self.class}#initialize_copy called!"
  end
end

class FooSet < Set
  def initialize_copy(other)
    puts "#{self.class}#initialize_copy called!"
  end
end

obj = FooObject.new
obj.dup

set = FooSet.new
set.dup

CRuby 2.7.4

FooObject#initialize_copy called!
FooSet#initialize_copy called!

CRuby 3.0.2

FooObject#initialize_copy called!
FooSet#initialize_copy called!

JRuby 9.3.1.0

FooObject#initialize_copy called!
@headius
Copy link
Member

headius commented Oct 26, 2021

Aha, just a missing bit from our native port I guess. Quick fix.

@headius headius added this to the JRuby 9.3.2.0 milestone Oct 26, 2021
@headius
Copy link
Member

headius commented Oct 26, 2021

FWIW we do intend for our native Set to work exactly like the CRuby version, so this should get some specs to cover subclass usage.

@headius
Copy link
Member

headius commented Oct 26, 2021

Also affects 9.2.19 so I will retarget.

@headius headius modified the milestones: JRuby 9.3.2.0, JRuby 9.2.20.0 Oct 26, 2021
headius added a commit to headius/jruby that referenced this issue Oct 26, 2021
headius added a commit to headius/jruby that referenced this issue Oct 26, 2021
@headius
Copy link
Member

headius commented Oct 26, 2021

Fixed by #6910.

@headius headius closed this as completed Oct 26, 2021
@headius
Copy link
Member

headius commented Oct 26, 2021

This will be in 9.2.20 and 9.3.2.

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