diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-11-07 15:51:00 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-11-07 15:51:00 +0900 |
| commit | d3b323cf2f2f71c8f5dc823bd52b1a30c2c6ec91 (patch) | |
| tree | 646d70490d7501f8246543a18945f9db47c6a037 /src/variable.c | |
| parent | 8bad1954a40c258679f51d4e97acc4f7e4697309 (diff) | |
| download | mruby-d3b323cf2f2f71c8f5dc823bd52b1a30c2c6ec91.tar.gz mruby-d3b323cf2f2f71c8f5dc823bd52b1a30c2c6ec91.zip | |
PR #2521 did not work for singleton classes for non-class objects; fix #3003
Diffstat (limited to 'src/variable.c')
| -rw-r--r-- | src/variable.c | 32 |
1 files changed, 26 insertions, 6 deletions
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); |
