summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Gruber <luke.gruber@shopify.com>2025-12-01 16:51:29 -0500
committerGitHub <noreply@github.com>2025-12-01 16:51:29 -0500
commita8b49ab48703dfb8862ca28a443da0e764d692c6 (patch)
treec1c6c644e544f0c641560292662fdbf1611ea172
parentf92001344d0595bb6ef3a9576853edf1fa7588ca (diff)
Test CC invalidation for singleton classes of objects (#15360)
I made a recent change where all the tests passed but it turns out it was still wrong. We didn't have any tests for CC invalidation on singletons of objects that aren't classes or modules.
-rw-r--r--test/ruby/test_class.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index f40817e7a1..10b7655e9a 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -887,4 +887,34 @@ CODE
class C; end
end;
end
+
+ def test_singleton_cc_invalidation
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}")
+ begin;
+ class T
+ def hi
+ "hi"
+ end
+ end
+
+ t = T.new
+ t.singleton_class
+
+ def hello(t)
+ t.hi
+ end
+
+ 5.times do
+ hello(t) # populate inline cache on `t.singleton_class`.
+ end
+
+ class T
+ remove_method :hi # invalidate `t.singleton_class` ccs for `hi`
+ end
+
+ assert_raise NoMethodError do
+ hello(t)
+ end
+ end;
+ end
end