Skip to content

Commit

Permalink
Fix clone metaclass setup based on current MRI. Fixes #4229.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 8, 2016
1 parent 48cc9ba commit afe5e51
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ public IRubyObject rbClone() {

// We're cloning ourselves, so we know the result should be a RubyObject
RubyBasicObject clone = (RubyBasicObject)getMetaClass().getRealClass().allocate();
clone.setMetaClass(getSingletonClassClone());
clone.setMetaClass(getSingletonClassCloneAndAttach(clone));
if (isTaint()) clone.setTaint(true);

initCopy(runtime.getCurrentContext(), clone, this, true);
Expand All @@ -968,21 +968,25 @@ public IRubyObject rbClone() {
return clone;
}

protected RubyClass getSingletonClassClone() {
return getSingletonClassCloneAndAttach(UNDEF);
}

/** rb_singleton_class_clone
*
* Will make sure that if the current objects class is a
* singleton, it will get cloned.
*
* @return either a real class, or a clone of the current singleton class
*/
protected RubyClass getSingletonClassClone() {
protected RubyClass getSingletonClassCloneAndAttach(IRubyObject attach) {
RubyClass klass = getMetaClass();

if (!klass.isSingleton()) {
return klass;
}

MetaClass clone = new MetaClass(getRuntime(), klass.getSuperClass(), ((MetaClass) klass).getAttached());
RubyClass clone = new MetaClass(getRuntime(), klass.getSuperClass(), attach);
clone.flags = flags;

if (this instanceof RubyClass) {
Expand Down

0 comments on commit afe5e51

Please sign in to comment.