Fix cvar, ivar, const and method can be removed to frozen object
MODIFY
mrbgems/mruby-metaprog/src/metaprog.c
mrbgems/mruby-metaprog/src/metaprog.c
@@ -641,6 +641,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod)
mrb_value *argv;
mrb_get_args(mrb, "*", &argv, &argc);
+ mrb_check_frozen(mrb, mrb_obj_ptr(mod));
while (argc--) {
remove_method(mrb, mod, mrb_obj_to_sym(mrb, *argv));
argv++;

MODIFY
mrbgems/mruby-metaprog/test/metaprog.rb
mrbgems/mruby-metaprog/test/metaprog.rb
@@ -298,6 +298,9 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do
assert_raise(NameError) do
Test4RemoveClassVariable.remove_class_variable(:@v)
end
+ assert_raise(FrozenError) do
+ Test4RemoveClassVariable.freeze.remove_class_variable(:@@cv)
+ end
end
assert('Module#remove_method', '15.2.2.4.41') do
@@ -317,6 +320,7 @@ assert('Module#remove_method', '15.2.2.4.41') do
assert_same klass, klass.class_eval{ remove_method :hello }
assert_true klass.instance_methods.include? :hello
assert_false klass.instance_methods(false).include? :hello
+ assert_raise(FrozenError) { klass.freeze.remove_method :m }
end
assert('Module.nesting', '15.2.2.2.2') do

MODIFY
src/variable.c
src/variable.c
@@ -521,6 +521,7 @@ mrb_obj_iv_inspect(mrb_state *mrb, struct RObject *obj)
MRB_API mrb_value
mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym)
{
+ mrb_check_frozen(mrb, mrb_obj_ptr(obj));
if (obj_iv_p(obj)) {
iv_tbl *t = mrb_obj_ptr(obj)->iv;
mrb_value val;

MODIFY
test/t/kernel.rb
test/t/kernel.rb
@@ -404,6 +404,7 @@ assert('Kernel#remove_instance_variable', '15.3.1.3.41') do
assert_equal nil, tri.var
assert_raise(NameError) { tri.remove }
assert_raise(NameError) { tri.remove_instance_variable(:var) }
+ assert_raise(FrozenError) { tri.freeze.remove }
end
# Kernel#require is defined in mruby-require. '15.3.1.3.42'

MODIFY
test/t/module.rb
test/t/module.rb
@@ -262,6 +262,7 @@ assert('Module#remove_const', '15.2.2.4.40') do
%i[x X!].each do |n|
assert_raise(NameError) { Test4RemoveConst.remove_const(n) }
end
+ assert_raise(FrozenError) { Test4RemoveConst.freeze.remove_const(:A) }
end
assert('Module#const_missing', '15.2.2.4.22') do

Fix cvar, ivar, const and method can be removed to frozen object