ruby-changes:55943
From: Nobuyoshi <ko1@a...>
Date: Sat, 1 Jun 2019 02:44:28 +0900 (JST)
Subject: [ruby-changes:55943] Nobuyoshi Nakada: c1e5299787 (trunk): Fix FrozenError when assigning frozen class to constant
https://git.ruby-lang.org/ruby.git/commit/?id=c1e5299787 From c1e52997870a63168835fde49562cb3c822c968a Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 1 Jun 2019 01:46:23 +0900 Subject: 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] diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 6851185..3786eed 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -584,6 +584,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L584 assert_equal(prefix+"N", m.const_get(:N).name) assert_equal(prefix+"O", m.const_get(:O).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 def test_private_class_method diff --git a/variable.c b/variable.c index ea618ce..ebfdf0d 100644 --- a/variable.c +++ b/variable.c @@ -2733,8 +2733,10 @@ static void https://github.com/ruby/ruby/blob/trunk/variable.c#L2733 set_namespace_path(VALUE named_namespace, VALUE namespace_path) { struct rb_id_table *const_table = RCLASS_CONST_TBL(named_namespace); - - rb_ivar_set(named_namespace, classpath, namespace_path); + if (!RCLASS_IV_TBL(named_namespace)) { + RCLASS_IV_TBL(named_namespace) = st_init_numtable(); + } + rb_class_ivar_set(named_namespace, classpath, namespace_path); if (const_table) { rb_id_table_foreach(const_table, set_namespace_path_i, &namespace_path); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/