diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2020-11-11 16:38:03 -0500 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2020-11-16 17:41:17 -0500 |
commit | ebb96fa8808317ad53a4977bff26cf755d68077e (patch) | |
tree | b7e3dd43bbc16ce71235b773df598f8138cb1065 /ruby_atomic.h | |
parent | 084e7e31b257f6ac859769553b4c1c6ca2930152 (diff) |
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 <ufuk.kayserilioglu@shopify.com>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3761
Diffstat (limited to 'ruby_atomic.h')
0 files changed, 0 insertions, 0 deletions