2010/1/13 Marc-Andre Lafortune <redmine / ruby-lang.org>:
> I feel that obj.is_a?(BasicObject) should be expected to return true for any obj and that BasicObject.clone should raise an error. The same should be true for Object in 1.8.
I agree with you.
Can I commit the following patch, Matz?
diff --git a/class.c b/class.c
index 6674ae1..fed2edf 100644
--- a/class.c
+++ b/class.c
@@ -180,6 +180,9 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
VALUE
rb_class_init_copy(VALUE clone, VALUE orig)
{
+ if (orig == rb_cBasicObject) {
+ rb_raise(rb_eTypeError, "can't copy the root class");
+ }
if (RCLASS_SUPER(clone) != 0 || clone == rb_cBasicObject) {
rb_raise(rb_eTypeError, "already initialized class");
}
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index b444d4e..3a0ced8 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -181,6 +181,8 @@ class TestClass < Test::Unit::TestCase
o = Object.new
c = class << o; self; end
assert_raise(TypeError) { c.dup }
+
+ assert_raise(TypeError) { BasicObject.dup }
end
def test_singleton_class
--
Shugo Maeda