From d3b323cf2f2f71c8f5dc823bd52b1a30c2c6ec91 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 7 Nov 2015 15:51:00 +0900 Subject: PR #2521 did not work for singleton classes for non-class objects; fix #3003 --- src/variable.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/variable.c') diff --git a/src/variable.c b/src/variable.c index efe6fad12..fa1389caf 100644 --- a/src/variable.c +++ b/src/variable.c @@ -759,17 +759,29 @@ MRB_API mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym) { struct RClass * cls = c; + mrb_value v; while (c) { - if (c->iv) { - iv_tbl *t = c->iv; - mrb_value v; - - if (iv_get(mrb, t, sym, &v)) - return v; + if (c->iv && iv_get(mrb, c->iv, sym, &v)) { + return v; } c = c->super; } + if (cls && cls->tt == MRB_TT_SCLASS) { + mrb_value klass; + + klass = mrb_obj_iv_get(mrb, (struct RObject *)cls, + mrb_intern_lit(mrb, "__attached__")); + c = mrb_class_ptr(klass); + if (c->tt == MRB_TT_CLASS) { + while (c) { + if (c->iv && iv_get(mrb, c->iv, sym, &v)) { + return v; + } + c = c->super; + } + } + } mrb_name_error(mrb, sym, "uninitialized class variable %S in %S", mrb_sym2str(mrb, sym), mrb_obj_value(cls)); /* not reached */ @@ -914,6 +926,14 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym) if (c->iv && iv_get(mrb, c->iv, sym, &v)) { return v; } + if (c->tt == MRB_TT_SCLASS) { + mrb_value klass; + klass = mrb_obj_iv_get(mrb, (struct RObject *)c, + mrb_intern_lit(mrb, "__attached__")); + c2 = mrb_class_ptr(klass); + if (c2->tt == MRB_TT_CLASS) + c = c2; + } c2 = c; for (;;) { c2 = mrb_class_outer_module(mrb, c2); -- cgit v1.2.3