Skip to content

Commit

Permalink
Fix 36fc1f1 not checking in the right location
Browse files Browse the repository at this point in the history
  • Loading branch information
bouk authored and clayton-shopify committed Jan 11, 2017
1 parent db1bd07 commit 6be5160
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,16 @@ 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);
}
}

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);
Expand Down
18 changes: 18 additions & 0 deletions test/t/nomethoderror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,21 @@ def foo
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

0 comments on commit 6be5160

Please sign in to comment.