diff options
author | nagachika <nagachika@ruby-lang.org> | 2021-03-20 14:26:30 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-03-20 14:26:30 +0900 |
commit | 82d72f14e7071218f3fd710f770d1ba31390f027 (patch) | |
tree | 5d5cad384cba513f46290df64835aafe7fb7c943 /time.c | |
parent | 6ef46f71c743507a0e2ae0eef14dce0539b0ff52 (diff) |
merge revision(s) ebb96fa8808317ad53a4977bff26cf755d68077e: [Backport #17321]
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>
---
class.c | 31 ++++++++++++++++++++++---------
test/ruby/test_class.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 9 deletions(-)
Diffstat (limited to 'time.c')
0 files changed, 0 insertions, 0 deletions