From f33cd1289e75c7091e61e54792a2b7e1f84ea697 Mon Sep 17 00:00:00 2001 From: Daniel Colson Date: Thu, 23 Oct 2025 17:47:58 -0400 Subject: [PATCH] ZJIT: Add tests for non-leaf classvar get and set (#14924) This commit adds tests that raise on `getclassvariable` and `setclassvariable` to exercise the non-leaf cases as suggested in https://github.com/ruby/ruby/pull/14918#discussion_r2453804603 --- test/ruby/test_zjit.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb index 13c7817017..e76e140ba1 100644 --- a/test/ruby/test_zjit.rb +++ b/test/ruby/test_zjit.rb @@ -1675,6 +1675,20 @@ class TestZJIT < Test::Unit::TestCase } end + def test_getclassvariable_raises + assert_compiles '"uninitialized class variable @@x in Foo"', %q{ + class Foo + def self.test = @@x + end + + begin + Foo.test + rescue NameError => e + e.message + end + } + end + def test_setclassvariable assert_compiles '42', %q{ class Foo @@ -1686,6 +1700,21 @@ class TestZJIT < Test::Unit::TestCase } end + def test_setclassvariable_raises + assert_compiles '"can\'t modify frozen #: Foo"', %q{ + class Foo + def self.test = @@x = 42 + freeze + end + + begin + Foo.test + rescue FrozenError => e + e.message + end + } + end + def test_attr_reader assert_compiles '[4, 4]', %q{ class C