ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100801] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect
@ 2020-11-11 22:32 ufuk
  2020-11-18 19:02 ` [ruby-core:100938] " merch-redmine
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ufuk @ 2020-11-11 22:32 UTC (permalink / raw
  To: ruby-core

Issue #17321 has been reported by ufuk (Ufuk Kayserilioglu).

----------------------------------------
Bug #17321: Having a singleton class makes cloning imperfect
https://bugs.ruby-lang.org/issues/17321

* Author: ufuk (Ufuk Kayserilioglu)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-11-11T09:11:09Z master fa3670e6e4) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------

## Problem
---
Running the following reproduction script:
```ruby
class Foo
  def self.foo; end
end

def report(klass, name)
  puts "  #{name}.instance_methods(false): #{klass.instance_methods(false)}"
end

def clone_and_compare(obj)
  cln = obj.clone

  report(obj.singleton_class, "obj.singleton_class")
  report(cln.singleton_class, "cln.singleton_class")
  report(obj.singleton_class.singleton_class, "obj.singleton_class.singleton_class")
  report(cln.singleton_class.singleton_class, "cln.singleton_class.singleton_class")
end

puts "## Case 1"
obj = Foo.new
clone_and_compare(obj)

puts "## Case 2"
obj = Foo.new
obj.singleton_class
clone_and_compare(obj)

puts "## Case 3"
obj = Foo.new
obj.singleton_class.singleton_class.send(:define_method, :method_on_s2) {}
clone_and_compare(obj)
```
gives the following output:
```
## Case 1
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): []
## Case 2
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): [:foo]
## Case 3
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
  cln.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
```

`Case 2` is surprising, because the cloned object has different contents to the original. 
It is surprising that `clone.singleton_class.singleton_class` has the method `:foo` whereas 
`obj.singleton_class.singleton_class` does not have any methods. 

`Case 3` suggests, however, that `clone.singleton_class.singleton_class` should have the 
same methods as the ones on `obj.singleton_class.singleton_class`.

This reproduction script gives the same output all the way from Ruby 2.0 up to Ruby-HEAD: 
https://wandbox.org/permlink/hRM9OMgtd6nuscRz

## Fix
---

@alanwu and me have put together a PR that makes `Case 2` output identical to `Case 1` output:
https://github.com/ruby/ruby/pull/3761





-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:100938] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect
  2020-11-11 22:32 [ruby-core:100801] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect ufuk
@ 2020-11-18 19:02 ` merch-redmine
  2020-11-24 19:44 ` [ruby-core:101053] " ufuk
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2020-11-18 19:02 UTC (permalink / raw
  To: ruby-core

Issue #17321 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

Fixed by commit:ebb96fa8808317ad53a4977bff26cf755d68077e.

----------------------------------------
Bug #17321: Having a singleton class makes cloning imperfect
https://bugs.ruby-lang.org/issues/17321#change-88592

* Author: ufuk (Ufuk Kayserilioglu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-11-11T09:11:09Z master fa3670e6e4) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------

## Problem
---
Running the following reproduction script:
```ruby
class Foo
  def self.foo; end
end

def report(klass, name)
  puts "  #{name}.instance_methods(false): #{klass.instance_methods(false)}"
end

def clone_and_compare(obj)
  cln = obj.clone

  report(obj.singleton_class, "obj.singleton_class")
  report(cln.singleton_class, "cln.singleton_class")
  report(obj.singleton_class.singleton_class, "obj.singleton_class.singleton_class")
  report(cln.singleton_class.singleton_class, "cln.singleton_class.singleton_class")
end

puts "## Case 1"
obj = Foo.new
clone_and_compare(obj)

puts "## Case 2"
obj = Foo.new
obj.singleton_class
clone_and_compare(obj)

puts "## Case 3"
obj = Foo.new
obj.singleton_class.singleton_class.send(:define_method, :method_on_s2) {}
clone_and_compare(obj)
```
gives the following output:
```
## Case 1
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): []
## Case 2
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): [:foo]
## Case 3
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
  cln.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
```

`Case 2` is surprising, because the cloned object has different contents to the original. 
It is surprising that `clone.singleton_class.singleton_class` has the method `:foo` whereas 
`obj.singleton_class.singleton_class` does not have any methods. 

`Case 3` suggests, however, that `clone.singleton_class.singleton_class` should have the 
same methods as the ones on `obj.singleton_class.singleton_class`.

This reproduction script gives the same output all the way from Ruby 2.0 up to Ruby-HEAD: 
https://wandbox.org/permlink/hRM9OMgtd6nuscRz

## Fix
---

@alanwu and me have put together a PR that makes `Case 2` output identical to `Case 1` output:
https://github.com/ruby/ruby/pull/3761





-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:101053] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect
  2020-11-11 22:32 [ruby-core:100801] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect ufuk
  2020-11-18 19:02 ` [ruby-core:100938] " merch-redmine
@ 2020-11-24 19:44 ` ufuk
  2020-11-24 20:12 ` [ruby-core:101054] " merch-redmine
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ufuk @ 2020-11-24 19:44 UTC (permalink / raw
  To: ruby-core

Issue #17321 has been updated by ufuk (Ufuk Kayserilioglu).


@jeremyevans0 Thanks for closing the issue. 

Can we get this fix backported to 2.5, 2.6 and 2.7 please? As noted in the original report, this bug is present on all the way back to 2.0.

Thank you!

----------------------------------------
Bug #17321: Having a singleton class makes cloning imperfect
https://bugs.ruby-lang.org/issues/17321#change-88725

* Author: ufuk (Ufuk Kayserilioglu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-11-11T09:11:09Z master fa3670e6e4) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------

## Problem
---
Running the following reproduction script:
```ruby
class Foo
  def self.foo; end
end

def report(klass, name)
  puts "  #{name}.instance_methods(false): #{klass.instance_methods(false)}"
end

def clone_and_compare(obj)
  cln = obj.clone

  report(obj.singleton_class, "obj.singleton_class")
  report(cln.singleton_class, "cln.singleton_class")
  report(obj.singleton_class.singleton_class, "obj.singleton_class.singleton_class")
  report(cln.singleton_class.singleton_class, "cln.singleton_class.singleton_class")
end

puts "## Case 1"
obj = Foo.new
clone_and_compare(obj)

puts "## Case 2"
obj = Foo.new
obj.singleton_class
clone_and_compare(obj)

puts "## Case 3"
obj = Foo.new
obj.singleton_class.singleton_class.send(:define_method, :method_on_s2) {}
clone_and_compare(obj)
```
gives the following output:
```
## Case 1
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): []
## Case 2
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): [:foo]
## Case 3
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
  cln.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
```

`Case 2` is surprising, because the cloned object has different contents to the original. 
It is surprising that `clone.singleton_class.singleton_class` has the method `:foo` whereas 
`obj.singleton_class.singleton_class` does not have any methods. 

`Case 3` suggests, however, that `clone.singleton_class.singleton_class` should have the 
same methods as the ones on `obj.singleton_class.singleton_class`.

This reproduction script gives the same output all the way from Ruby 2.0 up to Ruby-HEAD: 
https://wandbox.org/permlink/hRM9OMgtd6nuscRz

## Fix
---

@alanwu and me have put together a PR that makes `Case 2` output identical to `Case 1` output:
https://github.com/ruby/ruby/pull/3761





-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:101054] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect
  2020-11-11 22:32 [ruby-core:100801] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect ufuk
  2020-11-18 19:02 ` [ruby-core:100938] " merch-redmine
  2020-11-24 19:44 ` [ruby-core:101053] " ufuk
@ 2020-11-24 20:12 ` merch-redmine
  2021-03-20  6:02 ` [ruby-core:102948] " nagachika00
  2021-04-05  0:19 ` [ruby-core:103231] " usa
  4 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2020-11-24 20:12 UTC (permalink / raw
  To: ruby-core

Issue #17321 has been updated by jeremyevans0 (Jeremy Evans).

Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED

ufuk (Ufuk Kayserilioglu) wrote in #note-2:
> @jeremyevans0 Thanks for closing the issue. 
> 
> Can we get this fix backported to 2.5, 2.6 and 2.7 please? As noted in the original report, this bug is present all the way back to 2.0.

2.5 is unlikely, as that is in security maintenance mode and this is not a security fix.  2.6 and 2.7 are possibilities.  However, it is up to the branch maintainers whether this will be backported.  I've updated the backport information to show that a backport is requested.


----------------------------------------
Bug #17321: Having a singleton class makes cloning imperfect
https://bugs.ruby-lang.org/issues/17321#change-88726

* Author: ufuk (Ufuk Kayserilioglu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-11-11T09:11:09Z master fa3670e6e4) [x86_64-darwin19]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED
----------------------------------------

## Problem
---
Running the following reproduction script:
```ruby
class Foo
  def self.foo; end
end

def report(klass, name)
  puts "  #{name}.instance_methods(false): #{klass.instance_methods(false)}"
end

def clone_and_compare(obj)
  cln = obj.clone

  report(obj.singleton_class, "obj.singleton_class")
  report(cln.singleton_class, "cln.singleton_class")
  report(obj.singleton_class.singleton_class, "obj.singleton_class.singleton_class")
  report(cln.singleton_class.singleton_class, "cln.singleton_class.singleton_class")
end

puts "## Case 1"
obj = Foo.new
clone_and_compare(obj)

puts "## Case 2"
obj = Foo.new
obj.singleton_class
clone_and_compare(obj)

puts "## Case 3"
obj = Foo.new
obj.singleton_class.singleton_class.send(:define_method, :method_on_s2) {}
clone_and_compare(obj)
```
gives the following output:
```
## Case 1
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): []
## Case 2
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): [:foo]
## Case 3
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
  cln.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
```

`Case 2` is surprising, because the cloned object has different contents to the original. 
It is surprising that `clone.singleton_class.singleton_class` has the method `:foo` whereas 
`obj.singleton_class.singleton_class` does not have any methods. 

`Case 3` suggests, however, that `clone.singleton_class.singleton_class` should have the 
same methods as the ones on `obj.singleton_class.singleton_class`.

This reproduction script gives the same output all the way from Ruby 2.0 up to Ruby-HEAD: 
https://wandbox.org/permlink/hRM9OMgtd6nuscRz

## Fix
---

@alanwu and me have put together a PR that makes `Case 2` output identical to `Case 1` output:
https://github.com/ruby/ruby/pull/3761





-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:102948] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect
  2020-11-11 22:32 [ruby-core:100801] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect ufuk
                   ` (2 preceding siblings ...)
  2020-11-24 20:12 ` [ruby-core:101054] " merch-redmine
@ 2021-03-20  6:02 ` nagachika00
  2021-04-05  0:19 ` [ruby-core:103231] " usa
  4 siblings, 0 replies; 6+ messages in thread
From: nagachika00 @ 2021-03-20  6:02 UTC (permalink / raw
  To: ruby-core

Issue #17321 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE

ruby_2_7 82d72f14e7071218f3fd710f770d1ba31390f027 merged revision(s) ebb96fa8808317ad53a4977bff26cf755d68077e.

----------------------------------------
Bug #17321: Having a singleton class makes cloning imperfect
https://bugs.ruby-lang.org/issues/17321#change-91014

* Author: ufuk (Ufuk Kayserilioglu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-11-11T09:11:09Z master fa3670e6e4) [x86_64-darwin19]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE
----------------------------------------

## Problem
---
Running the following reproduction script:
```ruby
class Foo
  def self.foo; end
end

def report(klass, name)
  puts "  #{name}.instance_methods(false): #{klass.instance_methods(false)}"
end

def clone_and_compare(obj)
  cln = obj.clone

  report(obj.singleton_class, "obj.singleton_class")
  report(cln.singleton_class, "cln.singleton_class")
  report(obj.singleton_class.singleton_class, "obj.singleton_class.singleton_class")
  report(cln.singleton_class.singleton_class, "cln.singleton_class.singleton_class")
end

puts "## Case 1"
obj = Foo.new
clone_and_compare(obj)

puts "## Case 2"
obj = Foo.new
obj.singleton_class
clone_and_compare(obj)

puts "## Case 3"
obj = Foo.new
obj.singleton_class.singleton_class.send(:define_method, :method_on_s2) {}
clone_and_compare(obj)
```
gives the following output:
```
## Case 1
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): []
## Case 2
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): [:foo]
## Case 3
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
  cln.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
```

`Case 2` is surprising, because the cloned object has different contents to the original. 
It is surprising that `clone.singleton_class.singleton_class` has the method `:foo` whereas 
`obj.singleton_class.singleton_class` does not have any methods. 

`Case 3` suggests, however, that `clone.singleton_class.singleton_class` should have the 
same methods as the ones on `obj.singleton_class.singleton_class`.

This reproduction script gives the same output all the way from Ruby 2.0 up to Ruby-HEAD: 
https://wandbox.org/permlink/hRM9OMgtd6nuscRz

## Fix
---

@alanwu and me have put together a PR that makes `Case 2` output identical to `Case 1` output:
https://github.com/ruby/ruby/pull/3761





-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:103231] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect
  2020-11-11 22:32 [ruby-core:100801] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect ufuk
                   ` (3 preceding siblings ...)
  2021-03-20  6:02 ` [ruby-core:102948] " nagachika00
@ 2021-04-05  0:19 ` usa
  4 siblings, 0 replies; 6+ messages in thread
From: usa @ 2021-04-05  0:19 UTC (permalink / raw
  To: ruby-core

Issue #17321 has been updated by usa (Usaku NAKAMURA).

Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE to 2.5: REQUIRED, 2.6: DONE, 2.7: DONE

ruby_2_6 r67935 merged revision(s) ebb96fa8808317ad53a4977bff26cf755d68077e.

----------------------------------------
Bug #17321: Having a singleton class makes cloning imperfect
https://bugs.ruby-lang.org/issues/17321#change-91309

* Author: ufuk (Ufuk Kayserilioglu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-11-11T09:11:09Z master fa3670e6e4) [x86_64-darwin19]
* Backport: 2.5: REQUIRED, 2.6: DONE, 2.7: DONE
----------------------------------------

## Problem
---
Running the following reproduction script:
```ruby
class Foo
  def self.foo; end
end

def report(klass, name)
  puts "  #{name}.instance_methods(false): #{klass.instance_methods(false)}"
end

def clone_and_compare(obj)
  cln = obj.clone

  report(obj.singleton_class, "obj.singleton_class")
  report(cln.singleton_class, "cln.singleton_class")
  report(obj.singleton_class.singleton_class, "obj.singleton_class.singleton_class")
  report(cln.singleton_class.singleton_class, "cln.singleton_class.singleton_class")
end

puts "## Case 1"
obj = Foo.new
clone_and_compare(obj)

puts "## Case 2"
obj = Foo.new
obj.singleton_class
clone_and_compare(obj)

puts "## Case 3"
obj = Foo.new
obj.singleton_class.singleton_class.send(:define_method, :method_on_s2) {}
clone_and_compare(obj)
```
gives the following output:
```
## Case 1
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): []
## Case 2
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): []
  cln.singleton_class.singleton_class.instance_methods(false): [:foo]
## Case 3
  obj.singleton_class.instance_methods(false): []
  cln.singleton_class.instance_methods(false): []
  obj.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
  cln.singleton_class.singleton_class.instance_methods(false): [:method_on_s2]
```

`Case 2` is surprising, because the cloned object has different contents to the original. 
It is surprising that `clone.singleton_class.singleton_class` has the method `:foo` whereas 
`obj.singleton_class.singleton_class` does not have any methods. 

`Case 3` suggests, however, that `clone.singleton_class.singleton_class` should have the 
same methods as the ones on `obj.singleton_class.singleton_class`.

This reproduction script gives the same output all the way from Ruby 2.0 up to Ruby-HEAD: 
https://wandbox.org/permlink/hRM9OMgtd6nuscRz

## Fix
---

@alanwu and me have put together a PR that makes `Case 2` output identical to `Case 1` output:
https://github.com/ruby/ruby/pull/3761





-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-05  0:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-11 22:32 [ruby-core:100801] [Ruby master Bug#17321] Having a singleton class makes cloning imperfect ufuk
2020-11-18 19:02 ` [ruby-core:100938] " merch-redmine
2020-11-24 19:44 ` [ruby-core:101053] " ufuk
2020-11-24 20:12 ` [ruby-core:101054] " merch-redmine
2021-03-20  6:02 ` [ruby-core:102948] " nagachika00
2021-04-05  0:19 ` [ruby-core:103231] " usa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).