From bb8afd7265af41a75e8889774aa26f157f146380 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 6 Dec 2022 12:06:25 -0500 Subject: Freeze singleton class, not its origin Previously, when we froze an object, we froze `RCLASS_ORIGIN(object.singleton_class)`, which didn't freeze `object.singleton_class` when it has some prepended modules. Origin iclass are internal objects and users can't interact with them through Kernel#freeze?, Kernel#freeze, or any mutation method that checks the frozen status. So we shouldn't touch the origin iclasses when the frozen status should be visible. [Bug #19169] --- test/ruby/test_object.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index a9d5d4b13e..891ceff0c9 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -925,6 +925,19 @@ class TestObject < Test::Unit::TestCase end end + def test_singleton_class_freeze + x = Object.new + xs = x.singleton_class + x.freeze + assert_predicate(xs, :frozen?) + + y = Object.new + ys = y.singleton_class + ys.prepend(Module.new) + y.freeze + assert_predicate(ys, :frozen?, '[Bug #19169]') + end + def test_redef_method_missing bug5473 = '[ruby-core:40287]' ['ArgumentError.new("bug5473")', 'ArgumentError, "bug5473"', '"bug5473"'].each do |code| -- cgit v1.2.3