Project

General

Profile

« Previous | Next » 

Revision ebb96fa8

Added by alanwu (Alan Wu) almost 5 years ago

Fix singleton class cloning

Before this commit, clone gave different results depending on whether the original object
had an attached singleton class or not.

Consider the following setup:

class Foo; end Foo.singleton_class.define_method(:foo) {} obj = Foo.new obj.singleton_class if $call_singleton clone = obj.clone 

When $call_singleton = false, neither obj.singleton_class.singleton_class nor
clone.singleton_class.singleton_class own any methods.

However, when $call_singleton = true, clone.singleton_class.singleton_class would own a copy of
foo from Foo.singleton_class, even though obj.singleton_class.singleton_class does not.

The latter case is unexpected and results in a visibly different clone, depending on if the original object
had an attached class or not.

Co-authored-by: Ufuk Kayserilioglu