summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2020-04-14 23:49:28 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2020-04-14 23:49:29 -0700
commit79f3403be0cdbec814be29308c0583599ca5824f (patch)
tree3143b34566e4d5e07b153d892bdb03648c2c7459 /test/ruby
parent8355a998839f17ff214a89062821a0a4287f6a54 (diff)
Invalidate fastpath when calling attr_reader by super
The same bug as 8355a99883 existed in attr_reader too.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_super.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb
index 7cbe851fdf..78c8ee5dc2 100644
--- a/test/ruby/test_super.rb
+++ b/test/ruby/test_super.rb
@@ -604,7 +604,7 @@ class TestSuper < Test::Unit::TestCase
assert_equal :boo2, subklass.new.boo
end
- def test_super_attr_writer # Bug #16785
+ def test_super_attr_writer # [Bug #16785]
writer_class = Class.new do
attr_writer :test
end
@@ -633,4 +633,31 @@ class TestSuper < Test::Unit::TestCase
assert_equal 3, superwriter.instance_variable_get(:@test)
assert_equal 4, inherited.instance_variable_get(:@test)
end
+
+ def test_super_attr_reader
+ writer_class = Class.new do
+ attr_reader :test
+ end
+ superwriter_class = Class.new(writer_class) do
+ def initialize
+ @test = 1 # index: 1
+ end
+
+ def test
+ super
+ end
+ end
+ inherited_class = Class.new(superwriter_class) do
+ def initialize
+ @a = nil
+ @test = 2 # index: 2
+ end
+ end
+
+ superwriter = superwriter_class.new
+ assert_equal 1, superwriter.test # set ic->index of superwriter_class#test to 1
+
+ inherited = inherited_class.new
+ assert_equal 2, inherited.test # it may read index=1 while it should be index=2
+ end
end