object.c: avoid inadvertent symbol creation
* object.c (rb_mod_cvar_set): fix typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dc5b184b1f
commit
672b8bf1c0
14
object.c
14
object.c
@ -2296,12 +2296,22 @@ rb_mod_cvar_get(VALUE obj, VALUE iv)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
|
rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
|
||||||
{
|
{
|
||||||
ID id = rb_to_id(iv);
|
ID id;
|
||||||
|
|
||||||
|
if (SYMBOL_P(iv)) {
|
||||||
|
id = SYM2ID(iv);
|
||||||
if (!rb_is_class_id(id)) {
|
if (!rb_is_class_id(id)) {
|
||||||
rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name",
|
rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an class variable name",
|
||||||
QUOTE_ID(id));
|
QUOTE_ID(id));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (!rb_is_class_name(iv)) {
|
||||||
|
rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name",
|
||||||
|
QUOTE(iv));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
id = rb_to_id(iv);
|
||||||
|
}
|
||||||
rb_cvar_set(obj, id, val);
|
rb_cvar_set(obj, id, val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -581,6 +581,8 @@ class TestModule < Test::Unit::TestCase
|
|||||||
def test_const_set_invalid_name
|
def test_const_set_invalid_name
|
||||||
c1 = Class.new
|
c1 = Class.new
|
||||||
assert_raise(NameError) { c1.const_set(:foo, :foo) }
|
assert_raise(NameError) { c1.const_set(:foo, :foo) }
|
||||||
|
assert_raise(NameError) { c1.const_set("bar", :foo) }
|
||||||
|
assert_raise(TypeError) { c1.const_set(1, :foo) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_const_get_invalid_name
|
def test_const_get_invalid_name
|
||||||
@ -664,6 +666,8 @@ class TestModule < Test::Unit::TestCase
|
|||||||
assert_equal(:foo, c.class_variable_get(:@@foo))
|
assert_equal(:foo, c.class_variable_get(:@@foo))
|
||||||
assert_raise(NameError) { c.class_variable_get(:@@bar) } # c.f. instance_variable_get
|
assert_raise(NameError) { c.class_variable_get(:@@bar) } # c.f. instance_variable_get
|
||||||
assert_raise(NameError) { c.class_variable_get(:foo) }
|
assert_raise(NameError) { c.class_variable_get(:foo) }
|
||||||
|
assert_raise(NameError) { c.class_variable_get("bar") }
|
||||||
|
assert_raise(TypeError) { c.class_variable_get(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_variable_set
|
def test_class_variable_set
|
||||||
@ -671,6 +675,8 @@ class TestModule < Test::Unit::TestCase
|
|||||||
c.class_variable_set(:@@foo, :foo)
|
c.class_variable_set(:@@foo, :foo)
|
||||||
assert_equal(:foo, c.class_eval('@@foo'))
|
assert_equal(:foo, c.class_eval('@@foo'))
|
||||||
assert_raise(NameError) { c.class_variable_set(:foo, 1) }
|
assert_raise(NameError) { c.class_variable_set(:foo, 1) }
|
||||||
|
assert_raise(NameError) { c.class_variable_set("bar", 1) }
|
||||||
|
assert_raise(TypeError) { c.class_variable_set(1, 1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_variable_defined
|
def test_class_variable_defined
|
||||||
@ -679,6 +685,8 @@ class TestModule < Test::Unit::TestCase
|
|||||||
assert_equal(true, c.class_variable_defined?(:@@foo))
|
assert_equal(true, c.class_variable_defined?(:@@foo))
|
||||||
assert_equal(false, c.class_variable_defined?(:@@bar))
|
assert_equal(false, c.class_variable_defined?(:@@bar))
|
||||||
assert_raise(NameError) { c.class_variable_defined?(:foo) }
|
assert_raise(NameError) { c.class_variable_defined?(:foo) }
|
||||||
|
assert_raise(NameError) { c.class_variable_defined?("bar") }
|
||||||
|
assert_raise(TypeError) { c.class_variable_defined?(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_remove_class_variable
|
def test_remove_class_variable
|
||||||
|
@ -174,6 +174,8 @@ class TestObject < Test::Unit::TestCase
|
|||||||
assert_equal(:foo, o.instance_variable_get(:@foo))
|
assert_equal(:foo, o.instance_variable_get(:@foo))
|
||||||
assert_equal(nil, o.instance_variable_get(:@bar))
|
assert_equal(nil, o.instance_variable_get(:@bar))
|
||||||
assert_raise(NameError) { o.instance_variable_get(:foo) }
|
assert_raise(NameError) { o.instance_variable_get(:foo) }
|
||||||
|
assert_raise(NameError) { o.instance_variable_get("bar") }
|
||||||
|
assert_raise(TypeError) { o.instance_variable_get(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_variable_set
|
def test_instance_variable_set
|
||||||
@ -181,6 +183,8 @@ class TestObject < Test::Unit::TestCase
|
|||||||
o.instance_variable_set(:@foo, :foo)
|
o.instance_variable_set(:@foo, :foo)
|
||||||
assert_equal(:foo, o.instance_eval { @foo })
|
assert_equal(:foo, o.instance_eval { @foo })
|
||||||
assert_raise(NameError) { o.instance_variable_set(:foo, 1) }
|
assert_raise(NameError) { o.instance_variable_set(:foo, 1) }
|
||||||
|
assert_raise(NameError) { o.instance_variable_set("bar", 1) }
|
||||||
|
assert_raise(TypeError) { o.instance_variable_set(1, 1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_variable_defined
|
def test_instance_variable_defined
|
||||||
@ -189,6 +193,8 @@ class TestObject < Test::Unit::TestCase
|
|||||||
assert_equal(true, o.instance_variable_defined?(:@foo))
|
assert_equal(true, o.instance_variable_defined?(:@foo))
|
||||||
assert_equal(false, o.instance_variable_defined?(:@bar))
|
assert_equal(false, o.instance_variable_defined?(:@bar))
|
||||||
assert_raise(NameError) { o.instance_variable_defined?(:foo) }
|
assert_raise(NameError) { o.instance_variable_defined?(:foo) }
|
||||||
|
assert_raise(NameError) { o.instance_variable_defined?("bar") }
|
||||||
|
assert_raise(TypeError) { o.instance_variable_defined?(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_remove_instance_variable
|
def test_remove_instance_variable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user