From d5af8d785888f3af5efb844be5948df71d777b22 Mon Sep 17 00:00:00 2001 From: Satoshi Tagomori Date: Tue, 30 Dec 2025 14:46:19 +0900 Subject: Box: allocate classes as boxable when it happens in the root box Without this change, classes (including iclass) are allocated as un-boxable classes after initializing user boxes (after starting script evaluation). Under this situation, iclasses are created as un-boxabled class when core modules are included by a class in the root box, then it causes problems because it's in the root box but it can't have multiple classexts. This change makes it possible to allocate boxable classes even after initializing user boxes. Classes create in the root box will be boxable, and those can have 2 or more classexts. --- test/ruby/test_box.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_box.rb b/test/ruby/test_box.rb index 28c9dd02b0..763f6148cb 100644 --- a/test/ruby/test_box.rb +++ b/test/ruby/test_box.rb @@ -855,4 +855,20 @@ class TestBox < Test::Unit::TestCase assert_empty(Dir.children(tmpdir)) end end + + def test_root_box_iclasses_should_be_boxable + assert_separately([ENV_ENABLE_BOX], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true) + begin; + Ruby::Box.root.eval("class IMath; include Math; end") # (*) + module Math + def foo = :foo + end + # This test crashes here if iclasses (created at the line (*) is not boxable) + class IMath2; include Math; end + assert_equal :foo, IMath2.new.foo + assert_raise NoMethodError do + Ruby::Box.root.eval("IMath.new.foo") + end + end; + end end -- cgit v1.2.3