зеркало из https://github.com/github/ruby.git
Fix FrozenError when assigning frozen class to constant
* variable.c (set_namespace_path): modules/classes can get named by assignment to constant, even if frozen. [Bug #15891]
This commit is contained in:
Родитель
aeb9a0ca77
Коммит
c1e5299787
|
@ -584,6 +584,8 @@ class TestModule < Test::Unit::TestCase
|
||||||
assert_equal(prefix+"N", m.const_get(:N).name)
|
assert_equal(prefix+"N", m.const_get(:N).name)
|
||||||
assert_equal(prefix+"O", m.const_get(:O).name)
|
assert_equal(prefix+"O", m.const_get(:O).name)
|
||||||
assert_equal(prefix+"C", m.const_get(:C).name)
|
assert_equal(prefix+"C", m.const_get(:C).name)
|
||||||
|
c = m.class_eval("Bug15891 = Class.new.freeze")
|
||||||
|
assert_equal(prefix+"Bug15891", c.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_private_class_method
|
def test_private_class_method
|
||||||
|
|
|
@ -2733,8 +2733,10 @@ static void
|
||||||
set_namespace_path(VALUE named_namespace, VALUE namespace_path)
|
set_namespace_path(VALUE named_namespace, VALUE namespace_path)
|
||||||
{
|
{
|
||||||
struct rb_id_table *const_table = RCLASS_CONST_TBL(named_namespace);
|
struct rb_id_table *const_table = RCLASS_CONST_TBL(named_namespace);
|
||||||
|
if (!RCLASS_IV_TBL(named_namespace)) {
|
||||||
rb_ivar_set(named_namespace, classpath, namespace_path);
|
RCLASS_IV_TBL(named_namespace) = st_init_numtable();
|
||||||
|
}
|
||||||
|
rb_class_ivar_set(named_namespace, classpath, namespace_path);
|
||||||
if (const_table) {
|
if (const_table) {
|
||||||
rb_id_table_foreach(const_table, set_namespace_path_i, &namespace_path);
|
rb_id_table_foreach(const_table, set_namespace_path_i, &namespace_path);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче