mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Allow to include uninitialized modules [Bug #18177]
The module that is about to be included is considered initialized.
This commit is contained in:
parent
d2d549032c
commit
2e3d43e577
Notes:
git
2021-09-20 15:23:21 +09:00
2 changed files with 14 additions and 1 deletions
3
class.c
3
class.c
|
@ -917,7 +917,8 @@ ensure_includable(VALUE klass, VALUE module)
|
||||||
rb_class_modify_check(klass);
|
rb_class_modify_check(klass);
|
||||||
Check_Type(module, T_MODULE);
|
Check_Type(module, T_MODULE);
|
||||||
if (RMODULE_UNINITIALIZED(module)) {
|
if (RMODULE_UNINITIALIZED(module)) {
|
||||||
rb_raise(rb_eArgError, "uninitialized module");
|
RB_OBJ_WRITE(module, &RCLASS(module)->super, 0);
|
||||||
|
/* no more re-initialization */
|
||||||
}
|
}
|
||||||
if (!NIL_P(rb_refinement_module_get_refined_class(module))) {
|
if (!NIL_P(rb_refinement_module_get_refined_class(module))) {
|
||||||
rb_raise(rb_eArgError, "refinement module is not allowed");
|
rb_raise(rb_eArgError, "refinement module is not allowed");
|
||||||
|
|
|
@ -432,6 +432,18 @@ class TestModule < Test::Unit::TestCase
|
||||||
initialize_copy(Module.new)
|
initialize_copy(Module.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
m = Class.new(Module) do
|
||||||
|
def initialize_copy(other)
|
||||||
|
# leave uninitialized
|
||||||
|
end
|
||||||
|
end.new.dup
|
||||||
|
c = Class.new
|
||||||
|
assert_operator(c.include(m), :<, m)
|
||||||
|
cp = Module.instance_method(:initialize_copy)
|
||||||
|
assert_raise(TypeError) do
|
||||||
|
cp.bind_call(m, Module.new)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup
|
def test_dup
|
||||||
|
|
Loading…
Add table
Reference in a new issue