From ca2d47c20f91dc0ceec72052c28717bb0d7a74ef Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 18 Sep 2019 10:31:28 +0900 Subject: Fix `super` from aliased methods to work correctly; fix #4718 We needed to preserve the original method name somewhere. We kept it in the `env` structure pointed from aliased methods. #1457 and #1531 tried to address this issue. But this patch is more memory efficient. Limitation: this fix does not support `super` from methods defined by `define_method`. This limitation may be addressed in the future, but it's low priority. --- src/class.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/class.c') diff --git a/src/class.c b/src/class.c index 82ad3cf0a..1b0a37d05 100644 --- a/src/class.c +++ b/src/class.c @@ -1741,6 +1741,25 @@ mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b) { mrb_method_t m = mrb_method_search(mrb, c, b); + if (!MRB_METHOD_CFUNC_P(m)) { + struct RProc *p = MRB_METHOD_PROC(m); + + if (MRB_PROC_ENV_P(p)) { + MRB_PROC_ENV(p)->mid = b; + } + else { + struct RClass *tc = MRB_PROC_TARGET_CLASS(p); + struct REnv *e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, NULL); + + e->mid = b; + if (tc) { + e->c = tc; + mrb_field_write_barrier(mrb, (struct RBasic*)e, (struct RBasic*)tc); + } + p->e.env = e; + p->flags |= MRB_PROC_ENVSET; + } + } mrb_define_method_raw(mrb, c, a, m); } -- cgit v1.2.3