Commit 030dd665 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

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

parent ab5ffb30
...@@ -641,6 +641,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod) ...@@ -641,6 +641,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod)
mrb_value *argv; mrb_value *argv;
mrb_get_args(mrb, "*", &argv, &argc); mrb_get_args(mrb, "*", &argv, &argc);
mrb_check_frozen(mrb, mrb_obj_ptr(mod));
while (argc--) { while (argc--) {
remove_method(mrb, mod, mrb_obj_to_sym(mrb, *argv)); remove_method(mrb, mod, mrb_obj_to_sym(mrb, *argv));
argv++; argv++;
......
...@@ -298,6 +298,9 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do ...@@ -298,6 +298,9 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do
assert_raise(NameError) do assert_raise(NameError) do
Test4RemoveClassVariable.remove_class_variable(:@v) Test4RemoveClassVariable.remove_class_variable(:@v)
end end
assert_raise(FrozenError) do
Test4RemoveClassVariable.freeze.remove_class_variable(:@@cv)
end
end end
assert('Module#remove_method', '15.2.2.4.41') do assert('Module#remove_method', '15.2.2.4.41') do
...@@ -305,9 +308,9 @@ assert('Module#remove_method', '15.2.2.4.41') do ...@@ -305,9 +308,9 @@ assert('Module#remove_method', '15.2.2.4.41') do
class Parent class Parent
def hello def hello
end end
end end
class Child < Parent class Child < Parent
def hello def hello
end end
end end
...@@ -317,6 +320,7 @@ 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_same klass, klass.class_eval{ remove_method :hello }
assert_true klass.instance_methods.include? :hello assert_true klass.instance_methods.include? :hello
assert_false klass.instance_methods(false).include? :hello assert_false klass.instance_methods(false).include? :hello
assert_raise(FrozenError) { klass.freeze.remove_method :m }
end end
assert('Module.nesting', '15.2.2.2.2') do assert('Module.nesting', '15.2.2.2.2') do
......
...@@ -521,6 +521,7 @@ mrb_obj_iv_inspect(mrb_state *mrb, struct RObject *obj) ...@@ -521,6 +521,7 @@ mrb_obj_iv_inspect(mrb_state *mrb, struct RObject *obj)
MRB_API mrb_value MRB_API mrb_value
mrb_iv_remove(mrb_state *mrb, mrb_value obj, mrb_sym sym) 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)) { if (obj_iv_p(obj)) {
iv_tbl *t = mrb_obj_ptr(obj)->iv; iv_tbl *t = mrb_obj_ptr(obj)->iv;
mrb_value val; mrb_value val;
......
...@@ -404,6 +404,7 @@ assert('Kernel#remove_instance_variable', '15.3.1.3.41') do ...@@ -404,6 +404,7 @@ assert('Kernel#remove_instance_variable', '15.3.1.3.41') do
assert_equal nil, tri.var assert_equal nil, tri.var
assert_raise(NameError) { tri.remove } assert_raise(NameError) { tri.remove }
assert_raise(NameError) { tri.remove_instance_variable(:var) } assert_raise(NameError) { tri.remove_instance_variable(:var) }
assert_raise(FrozenError) { tri.freeze.remove }
end end
# Kernel#require is defined in mruby-require. '15.3.1.3.42' # Kernel#require is defined in mruby-require. '15.3.1.3.42'
......
...@@ -262,6 +262,7 @@ assert('Module#remove_const', '15.2.2.4.40') do ...@@ -262,6 +262,7 @@ assert('Module#remove_const', '15.2.2.4.40') do
%i[x X!].each do |n| %i[x X!].each do |n|
assert_raise(NameError) { Test4RemoveConst.remove_const(n) } assert_raise(NameError) { Test4RemoveConst.remove_const(n) }
end end
assert_raise(FrozenError) { Test4RemoveConst.freeze.remove_const(:A) }
end end
assert('Module#const_missing', '15.2.2.4.22') do assert('Module#const_missing', '15.2.2.4.22') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment