diff options
| author | John Hawthorn <john@hawthorn.email> | 2026-04-02 16:20:05 -0700 |
|---|---|---|
| committer | John Hawthorn <john@hawthorn.email> | 2026-05-13 13:40:46 -0700 |
| commit | 88095eb19621b80f3547abe32adbf3f3c82c42ad (patch) | |
| tree | 1df76908a50fb89682a75927edb647052558f664 /test | |
| parent | 40272b1de6f9fe55d79898a190db74c2c960e9ee (diff) | |
Remove CREF rewriting for cloned classes/modules
When a class or module was cloned, rb_vm_rewrite_cref would rewrite the
CREF chain of each cloned method to point at the new class. Remove this
special case so that clone behaves consistently with all other ways of
adopting a method.
This also removes the RCLASS_CLONED flag which was used to prevent
constant inline cache sharing between cloned classes [Bug #15877], and
the vm_cref_new_use_prev helper which only existed for CREF rewriting.
[Feature #21981]
Diffstat (limited to 'test')
| -rw-r--r-- | test/ruby/test_class.rb | 5 | ||||
| -rw-r--r-- | test/ruby/test_module.rb | 7 | ||||
| -rw-r--r-- | test/ruby/test_variable.rb | 13 |
3 files changed, 18 insertions, 7 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 8e3f3933b0..078f63ecd9 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -435,6 +435,7 @@ class TestClass < Test::Unit::TestCase end class CloneTest + TEST = :C0 def foo; TEST; end end @@ -448,8 +449,8 @@ class TestClass < Test::Unit::TestCase end def test_constant_access_from_method_in_cloned_class - assert_equal :C1, CloneTest1.new.foo, '[Bug #15877]' - assert_equal :C2, CloneTest2.new.foo, '[Bug #15877]' + assert_equal :C0, CloneTest1.new.foo, 'originally [Bug #15877], but behaviour changed' + assert_equal :C0, CloneTest2.new.foo, 'originally [Bug #15877], but behaviour changed' end def test_invalid_superclass diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 9ed6c1e321..1f5aa54c7d 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -2822,7 +2822,7 @@ class TestModule < Test::Unit::TestCase b = a.dup b.new.a = 'B' - assert_equal 'A', a.new.a, '[ruby-core:17019]' + assert_equal 'B', a.new.a, '[ruby-core:17019] behaviour changed: cvar resolves through original CREF' end Bug6891 = '[ruby-core:47241]' @@ -3265,6 +3265,7 @@ class TestModule < Test::Unit::TestCase end module CloneTestM0 + TEST = :M0 def foo; TEST; end end @@ -3288,8 +3289,8 @@ class TestModule < Test::Unit::TestCase assert_equal 1, m::C, '[ruby-core:47834]' assert_equal 1, m.m, '[ruby-core:47834]' - assert_equal :M1, CloneTestC1.new.foo, '[Bug #15877]' - assert_equal :M2, CloneTestC2.new.foo, '[Bug #15877]' + assert_equal :M0, CloneTestC1.new.foo, 'originally [Bug #15877], but behaviour changed' + assert_equal :M0, CloneTestC2.new.foo, 'originally [Bug #15877], but behaviour changed' end def test_clone_freeze diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb index f3484fddce..a305ad6b2a 100644 --- a/test/ruby/test_variable.rb +++ b/test/ruby/test_variable.rb @@ -50,6 +50,11 @@ class TestVariable < Test::Unit::TestCase end Zeus = Gods.clone + class Zeus + def ruler5 + @@rule + end + end def test_cloned_allows_setting_cvar Zeus.class_variable_set(:@@rule, "Athena") @@ -58,8 +63,12 @@ class TestVariable < Test::Unit::TestCase zeus = Zeus.new.ruler0 assert_equal "Cronus", god - assert_equal "Athena", zeus - assert_not_equal god.object_id, zeus.object_id + assert_equal "Cronus", zeus + + assert_equal "Athena", Zeus.new.ruler5 + + assert_equal "Cronus", Gods.class_variable_get(:@@rule) + assert_equal "Athena", Zeus.class_variable_get(:@@rule) end def test_singleton_class_included_class_variable |
