vm.c (check_target_class): raise error if target_class is NULL

It fixes a bug that instance_eval for immediate objects defines methods
in Object, instead of raising error.

```ruby
1.instance_eval do
  def foo
    p :foo
  end
end
```
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-12-13 10:49:14 +09:00
parent 7ad657b532
commit 3bd2c56dae
+1 -1
View File
@@ -1290,7 +1290,7 @@ check_target_class(mrb_state *mrb)
{
struct RClass *target = CI_TARGET_CLASS(mrb->c->ci);
if (!target) {
return mrb->object_class;
mrb_raise(mrb, E_TYPE_ERROR, "no class/module to add method");
}
return target;
}