Fix not checking in the right location
MODIFY
src/error.c
src/error.c
@@ -280,8 +280,6 @@ mrb_exc_set(mrb_state *mrb, mrb_value exc)
mrb->exc = 0;
}
else {
- if (!mrb_obj_is_kind_of(mrb, exc, mrb->eException_class))
- mrb_raise(mrb, E_TYPE_ERROR, "exception object expected");
mrb->exc = mrb_obj_ptr(exc);
}
}
@@ -289,6 +287,9 @@ mrb_exc_set(mrb_state *mrb, mrb_value exc)
MRB_API mrb_noreturn void
mrb_exc_raise(mrb_state *mrb, mrb_value exc)
{
+ if (!mrb_obj_is_kind_of(mrb, exc, mrb->eException_class)) {
+ mrb_raise(mrb, E_TYPE_ERROR, "exception object expected");
+ }
mrb_exc_set(mrb, exc);
if (!mrb->gc.out_of_memory) {
exc_debug_info(mrb, mrb->exc);

MODIFY
test/t/nomethoderror.rb
test/t/nomethoderror.rb
@@ -51,3 +51,21 @@ assert('Can still call super when BasicObject#method_missing is removed') do
end
end
end
+
+assert("NoMethodError#new does not return an exception") do
+ begin
+ class << NoMethodError
+ def new(*)
+ nil
+ end
+ end
+
+ assert_raise(TypeError) do
+ Object.q
+ end
+ ensure
+ class << NoMethodError
+ remove_method :new
+ end
+ end
+end

Fix 36fc1f14 not checking in the right location