Forum: Ruby-core [ruby-trunk - Bug #7216][Open] object.c defines clone method for objects that cannot be cloned.

Posted by therevmj (Michael Johnson) (Guest)
on 2012-10-26 02:19
(Received via mailing list)
Issue #7216 has been reported by therevmj (Michael Johnson).

----------------------------------------
Bug #7216: object.c defines clone method for objects that cannot be 
cloned.
https://bugs.ruby-lang.org/issues/7216

Author: therevmj (Michael Johnson)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
ruby -v: all versions up to current trunk


As the subject says, in object.c, the clone method is defined and then 
special cased for certain object types.  The end result is that all 
respond_to?(:clone) returns true for all objects, but then thows an 
fatal error in some cases.  Here is an appropriate example:

>> a = true
=> true
>> a.respond_to?(:clone)
=> true
>> a.clone
TypeError: can't clone TrueClass
  from (irb):3:in `clone'
  from (irb):3

Ultimately, the objects that do no respond to 'clone' should have it 
removed so that the respond_to? method returns false.
Posted by mame (Yusuke Endoh) (Guest)
on 2012-11-05 14:27
(Received via mailing list)
Issue #7216 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to akr (Akira Tanaka)
Target version set to 2.0.0

Akr-san, what do you think?

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Bug #7216: object.c defines clone method for objects that cannot be 
cloned.
https://bugs.ruby-lang.org/issues/7216#change-32416

Author: therevmj (Michael Johnson)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: core
Target version: 2.0.0
ruby -v: all versions up to current trunk


As the subject says, in object.c, the clone method is defined and then 
special cased for certain object types.  The end result is that all 
respond_to?(:clone) returns true for all objects, but then thows an 
fatal error in some cases.  Here is an appropriate example:

>> a = true
=> true
>> a.respond_to?(:clone)
=> true
>> a.clone
TypeError: can't clone TrueClass
  from (irb):3:in `clone'
  from (irb):3

Ultimately, the objects that do no respond to 'clone' should have it 
removed so that the respond_to? method returns false.
Posted by Tanaka Akira (Guest)
on 2012-11-06 11:24
(Received via mailing list)
2012/11/5 mame (Yusuke Endoh) <mame@tsg.ne.jp>:
>
> Issue #7216 has been updated by mame (Yusuke Endoh).

> Akr-san, what do you think?

It may be good idea.

The root problem is that Liskov substitution principle is violated
between Object and TrueClass.
(Object is clonable but its subclass, TrueClass, is not.)

So, such unprincipled classes may have responsibility to
undefine/unimplement methods which don't work.

I feel it's better to ask matz.
Posted by Thomas Sawyer (7rans)
on 2013-02-17 19:51
(Received via mailing list)
Issue #7216 has been updated by trans (Thomas Sawyer).


This is true for class method #allocate too.
----------------------------------------
Bug #7216: object.c defines clone method for objects that cannot be 
cloned.
https://bugs.ruby-lang.org/issues/7216#change-36449

Author: therevmj (Michael Johnson)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: core
Target version: 2.0.0
ruby -v: all versions up to current trunk


As the subject says, in object.c, the clone method is defined and then 
special cased for certain object types.  The end result is that all 
respond_to?(:clone) returns true for all objects, but then thows an 
fatal error in some cases.  Here is an appropriate example:

>> a = true
=> true
>> a.respond_to?(:clone)
=> true
>> a.clone
TypeError: can't clone TrueClass
  from (irb):3:in `clone'
  from (irb):3

Ultimately, the objects that do no respond to 'clone' should have it 
removed so that the respond_to? method returns false.
Posted by mame (Yusuke Endoh) (Guest)
on 2013-02-18 16:14
(Received via mailing list)
Issue #7216 has been updated by mame (Yusuke Endoh).

Assignee changed from akr (Akira Tanaka) to matz (Yukihiro Matsumoto)
Target version changed from 2.0.0 to next minor


----------------------------------------
Bug #7216: object.c defines clone method for objects that cannot be 
cloned.
https://bugs.ruby-lang.org/issues/7216#change-36540

Author: therevmj (Michael Johnson)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
ruby -v: all versions up to current trunk


As the subject says, in object.c, the clone method is defined and then 
special cased for certain object types.  The end result is that all 
respond_to?(:clone) returns true for all objects, but then thows an 
fatal error in some cases.  Here is an appropriate example:

>> a = true
=> true
>> a.respond_to?(:clone)
=> true
>> a.clone
TypeError: can't clone TrueClass
  from (irb):3:in `clone'
  from (irb):3

Ultimately, the objects that do no respond to 'clone' should have it 
removed so that the respond_to? method returns false.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.