Skip to content

Commit

Permalink
class/module statement should re-open; fix #3225
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Nov 14, 2016
1 parent 1422e57 commit 4f6cce0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ MRB_API struct RClass*
mrb_vm_define_module(mrb_state *mrb, mrb_value outer, mrb_sym id)
{
check_if_class_or_module(mrb, outer);
if (mrb_const_defined_at(mrb, outer, id)) {
mrb_value old = mrb_const_get(mrb, outer, id);

if (mrb_type(old) != MRB_TT_MODULE) {
mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a module", mrb_inspect(mrb, old));
}
return mrb_class_ptr(old);
}
return define_module(mrb, id, mrb_class_ptr(outer));
}

Expand Down Expand Up @@ -255,6 +263,21 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
s = 0;
}
check_if_class_or_module(mrb, outer);
if (mrb_const_defined_at(mrb, outer, id)) {
mrb_value old = mrb_const_get(mrb, outer, id);

if (mrb_type(old) != MRB_TT_CLASS) {
mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a class", mrb_inspect(mrb, old));
}
c = mrb_class_ptr(old);
if (s) {
/* check super class */
if (mrb_class_real(c->super) != s) {
mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for class %S", old);
}
}
return c;
}
c = define_class(mrb, id, s, mrb_class_ptr(outer));
mrb_class_inherited(mrb, mrb_class_real(c->super), c);

Expand Down

0 comments on commit 4f6cce0

Please sign in to comment.