super should not be called outside of a method; fix #2770

parent b3b6fe3c
...@@ -1222,6 +1222,13 @@ RETRY_TRY_BLOCK: ...@@ -1222,6 +1222,13 @@ RETRY_TRY_BLOCK:
int a = GETARG_A(i); int a = GETARG_A(i);
int n = GETARG_C(i); int n = GETARG_C(i);
if (mid == 0) {
mrb_value exc;
out_super:
exc = mrb_exc_new_str_lit(mrb, E_NOMETHOD_ERROR, "super called outside of method");
mrb->exc = mrb_obj_ptr(exc);
goto L_RAISE;
}
recv = regs[0]; recv = regs[0];
c = mrb->c->ci->target_class->super; c = mrb->c->ci->target_class->super;
m = mrb_method_search_vm(mrb, &c, mid); m = mrb_method_search_vm(mrb, &c, mid);
...@@ -1306,10 +1313,7 @@ RETRY_TRY_BLOCK: ...@@ -1306,10 +1313,7 @@ RETRY_TRY_BLOCK:
else { else {
struct REnv *e = uvenv(mrb, lv-1); struct REnv *e = uvenv(mrb, lv-1);
if (!e) { if (!e) {
mrb_value exc; goto out_super;
exc = mrb_exc_new_str_lit(mrb, E_NOMETHOD_ERROR, "super called outside of method");
mrb->exc = mrb_obj_ptr(exc);
goto L_RAISE;
} }
stack = e->stack + 1; stack = e->stack + 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment