summaryrefslogtreecommitdiff
path: root/test/ruby/test_variable.rb
diff options
context:
space:
mode:
authorlukeg <[email protected]>2023-01-14 16:52:29 -0500
committerPeter Zhu <[email protected]>2023-01-19 16:25:20 -0500
commitf66804e6f78ed4cf81896d2256743a820b05939a (patch)
treea7c981dcb2b9cf7b4f03ba471d26afa9c5c43a4f /test/ruby/test_variable.rb
parentbf3940a306c5292324caa0b4756b90411cc3cdf1 (diff)
don't allow setting class variable on module that's frozen [Bug #19341]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7124
Diffstat (limited to 'test/ruby/test_variable.rb')
-rw-r--r--test/ruby/test_variable.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb
index 9acba39f40..1e51ce060a 100644
--- a/test/ruby/test_variable.rb
+++ b/test/ruby/test_variable.rb
@@ -155,6 +155,21 @@ class TestVariable < Test::Unit::TestCase
end
end
+ def test_set_class_variable_on_frozen_object
+ set_cvar = EnvUtil.labeled_class("SetCVar")
+ set_cvar.class_eval "#{<<~"begin;"}\n#{<<~'end;'}"
+ begin;
+ def self.set(val)
+ @@a = val # inline cache
+ end
+ end;
+ set_cvar.set(1) # fill write cache
+ set_cvar.freeze
+ assert_raise(FrozenError) do
+ set_cvar.set(2) # hit write cache, but should check frozen status
+ end
+ end
+
def test_variable
assert_instance_of(Integer, $$)