mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
object.c: no TypeError at special const
* object.c (special_object_p): no longer raise a TypeError for Integer and Float, and return itself instead. [Feature#12979] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7a480ae850
commit
7f30d00b53
2 changed files with 19 additions and 2 deletions
17
object.c
17
object.c
|
@ -297,6 +297,19 @@ init_copy(VALUE dest, VALUE obj)
|
|||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
special_object_p(VALUE obj)
|
||||
{
|
||||
if (SPECIAL_CONST_P(obj)) return TRUE;
|
||||
switch (BUILTIN_TYPE(obj)) {
|
||||
case T_BIGNUM:
|
||||
case T_FLOAT:
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* obj.clone(freeze: true) -> an_object
|
||||
|
@ -345,7 +358,7 @@ rb_obj_clone2(int argc, VALUE *argv, VALUE obj)
|
|||
}
|
||||
}
|
||||
|
||||
if (rb_special_const_p(obj)) {
|
||||
if (special_object_p(obj)) {
|
||||
if (kwfreeze == Qfalse)
|
||||
rb_raise(rb_eArgError, "can't unfreeze %s", rb_obj_classname(obj));
|
||||
return obj;
|
||||
|
@ -424,7 +437,7 @@ rb_obj_dup(VALUE obj)
|
|||
{
|
||||
VALUE dup;
|
||||
|
||||
if (rb_special_const_p(obj)) {
|
||||
if (special_object_p(obj)) {
|
||||
return obj;
|
||||
}
|
||||
dup = rb_obj_alloc(rb_obj_class(obj));
|
||||
|
|
|
@ -23,6 +23,8 @@ class TestObject < Test::Unit::TestCase
|
|||
assert_equal true, true.dup
|
||||
assert_equal nil, nil.dup
|
||||
assert_equal false, false.dup
|
||||
x = 1 << 64; assert_equal x, x.dup
|
||||
x = 1.72723e-77; assert_equal x, x.dup
|
||||
|
||||
assert_raise(TypeError) do
|
||||
Object.new.instance_eval { initialize_copy(1) }
|
||||
|
@ -49,6 +51,8 @@ class TestObject < Test::Unit::TestCase
|
|||
assert_equal true, true.clone
|
||||
assert_equal nil, nil.clone
|
||||
assert_equal false, false.clone
|
||||
x = 1 << 64; assert_equal x, x.clone
|
||||
x = 1.72723e-77; assert_equal x, x.clone
|
||||
assert_raise(ArgumentError) {1.clone(freeze: false)}
|
||||
assert_raise(ArgumentError) {true.clone(freeze: false)}
|
||||
assert_raise(ArgumentError) {nil.clone(freeze: false)}
|
||||
|
|
Loading…
Reference in a new issue