Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to include uninitialized modules [Bug #18177] #4868

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion class.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ ensure_includable(VALUE klass, VALUE module)
rb_class_modify_check(klass);
Check_Type(module, T_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))) {
rb_raise(rb_eArgError, "refinement module is not allowed");
Expand Down
12 changes: 12 additions & 0 deletions test/ruby/test_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ def x
initialize_copy(Module.new)
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

def test_dup
Expand Down