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

Merge pull request #4758 from shuujii/implement-Ruby2.7-frozen-strings-from-Module-name

Implement Ruby2.7's frozen strings from `Module#name`
parents e348326f fb103c13
def assert_module_name(exp, mod)
assert "assert_module_name" do
act = mod.__send__(:name)
assert_equal exp, act
assert_predicate act, :frozen?
end
end
assert 'Module#<' do
a = Class.new
b = Class.new(a)
......@@ -58,17 +66,17 @@ assert 'Module#name' do
const_set :SetInner, Class.new
end
assert_equal 'Outer', Outer.name
assert_equal 'Outer::Inner', Outer::Inner.name
assert_equal 'Outer::SetInner', Outer::SetInner.name
assert_module_name 'Outer', Outer
assert_module_name 'Outer::Inner', Outer::Inner
assert_module_name 'Outer::SetInner', Outer::SetInner
outer = Module.new do
const_set :SetInner, Class.new
end
Object.const_set :SetOuter, outer
assert_equal 'SetOuter', SetOuter.name
assert_equal 'SetOuter::SetInner', SetOuter::SetInner.name
assert_module_name 'SetOuter', SetOuter
assert_module_name 'SetOuter::SetInner', SetOuter::SetInner
mod = Module.new
cls = Class.new
......
......@@ -76,6 +76,7 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb
name = mrb_str_dup(mrb, name);
mrb_str_cat_cstr(mrb, name, "::");
mrb_str_cat_cstr(mrb, name, mrb_sym_name(mrb, id));
MRB_SET_FROZEN_FLAG(mrb_obj_ptr(name));
}
mrb_obj_iv_set_force(mrb, (struct RObject*)c, nsym, name);
}
......@@ -1712,7 +1713,7 @@ mrb_class_path(mrb_state *mrb, struct RClass *c)
/* toplevel class/module */
return mrb_sym_str(mrb, mrb_symbol(path));
}
return mrb_str_dup(mrb, path);
return path;
}
MRB_API struct RClass*
......
......@@ -1123,7 +1123,7 @@ mrb_class_find_path(mrb_state *mrb, struct RClass *c)
iv_del(mrb, c->iv, mrb_intern_lit(mrb, "__outer__"), NULL);
iv_put(mrb, c->iv, mrb_intern_lit(mrb, "__classname__"), path);
mrb_field_write_barrier_value(mrb, (struct RBasic*)c, path);
path = mrb_str_dup(mrb, path);
MRB_SET_FROZEN_FLAG(mrb_obj_ptr(path));
}
return path;
}
......
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