don't allow setting class variable on module that's frozen [Bug #19341]
This commit is contained in:
parent
bf3940a306
commit
f66804e6f7
Notes:
git
2023-01-19 21:25:41 +00:00
@ -155,6 +155,21 @@ class TestVariable < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
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
|
def test_variable
|
||||||
assert_instance_of(Integer, $$)
|
assert_instance_of(Integer, $$)
|
||||||
|
|
||||||
|
@ -3939,6 +3939,7 @@ rb_class_ivar_set(VALUE obj, ID key, VALUE value)
|
|||||||
{
|
{
|
||||||
RUBY_ASSERT(RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE));
|
RUBY_ASSERT(RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE));
|
||||||
int found;
|
int found;
|
||||||
|
rb_check_frozen(obj);
|
||||||
|
|
||||||
RB_VM_LOCK_ENTER();
|
RB_VM_LOCK_ENTER();
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user