From 2b54c135ff3ae2fb362a5efaa542ec9236116add Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 6 Jun 2023 10:21:29 -0400 Subject: YJIT: Avoid identity-based known-class guards for IO objects (#7911) `IO#reopen` is very special in that it is able to change the class and singleton class of IO instances. In its presence, it is not correct to assume that IO instances has a stable class/singleton class and guard by comparing identity. --- test/ruby/test_yjit.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 6700e58176..115c1902f0 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -1277,6 +1277,18 @@ class TestYJIT < Test::Unit::TestCase RUBY end + def test_io_reopen_clobbering_singleton_class + assert_compiles(<<~RUBY, result: [:ok, :ok]) + def $stderr.to_i = :i + + def test = $stderr.to_i + + [test, test] + $stderr.reopen($stderr.dup) + [test, test].map { :ok unless _1 == :i } + RUBY + end + private def code_gc_helpers -- cgit v1.2.3