From 71efad1ed391ee0c5398a76306fdbaaadd4dc52e Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 9 Aug 2019 11:00:34 +0900 Subject: introduce RCLASS_CLONED flag for inline cache. Methods on duplicated class/module refer same constant inline cache (IC). Constant access lookup should be done for cloned class/modules but inline cache doesn't check it. To check it, this patch introduce new RCLASS_CLONED flag which are set when if class/module is cloned (both orig and dst). [Bug #15877] --- test/ruby/test_class.rb | 22 +++++++++++++--------- test/ruby/test_module.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 93278a918f..f07a1cdc40 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -329,18 +329,22 @@ class TestClass < Test::Unit::TestCase end; end - module M - C = 1 + class CloneTest + def foo; TEST; end + end - def self.m - C - end + CloneTest1 = CloneTest.clone + CloneTest2 = CloneTest.clone + class CloneTest1 + TEST = :C1 + end + class CloneTest2 + TEST = :C2 end - def test_constant_access_from_method_in_cloned_module # [ruby-core:47834] - m = M.dup - assert_equal 1, m::C - assert_equal 1, m.m + 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]' end def test_invalid_superclass diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index cf50db3374..b8d6ffb19d 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -2418,6 +2418,39 @@ class TestModule < Test::Unit::TestCase } end + module CloneTestM_simple + C = 1 + def self.m; C; end + end + + module CloneTestM0 + def foo; TEST; end + end + + CloneTestM1 = CloneTestM0.clone + CloneTestM2 = CloneTestM0.clone + module CloneTestM1 + TEST = :M1 + end + module CloneTestM2 + TEST = :M2 + end + class CloneTestC1 + include CloneTestM1 + end + class CloneTestC2 + include CloneTestM2 + end + + def test_constant_access_from_method_in_cloned_module + m = CloneTestM_simple.dup + 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]' + end + private def assert_top_method_is_private(method) -- cgit v1.2.3