Unverified Commit 1685c459 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4508 from...

Merge pull request #4508 from shuujii/fix-cvar-ivar-const-and-method-can-be-removed-to-frozen-object

Fix cvar, ivar, const and method can be removed to frozen object
parents e514264b 030dd665
......@@ -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++;
......
......@@ -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
......
......@@ -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;
......
......@@ -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'
......
......@@ -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
......
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