summaryrefslogtreecommitdiffhomepage
path: root/src/variable.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-11-08 23:51:15 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2016-11-08 23:51:15 +0900
commit872517dff372ee6fde92c71861abf6ab9fbab958 (patch)
treeba45f9e1b285df97a7e1e7cbe25d814e2e2eedc5 /src/variable.c
parent1142cf20370362ab2b974b235e7606246245ce23 (diff)
downloadmruby-872517dff372ee6fde92c71861abf6ab9fbab958.tar.gz
mruby-872517dff372ee6fde92c71861abf6ab9fbab958.zip
class variables in higher order have a priority; fix #3235
Diffstat (limited to 'src/variable.c')
-rw-r--r--src/variable.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/variable.c b/src/variable.c
index 3b5674923..29f43e69d 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -760,13 +760,15 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym)
{
struct RClass * cls = c;
mrb_value v;
+ int given = FALSE;
while (c) {
if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
- return v;
+ given = TRUE;
}
c = c->super;
}
+ if (given) return v;
if (cls && cls->tt == MRB_TT_SCLASS) {
mrb_value klass;
@@ -774,12 +776,14 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym)
mrb_intern_lit(mrb, "__attached__"));
c = mrb_class_ptr(klass);
if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) {
+ given = FALSE;
while (c) {
if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
- return v;
+ given = TRUE;
}
c = c->super;
}
+ if (given) return v;
}
}
mrb_name_error(mrb, sym, "uninitialized class variable %S in %S",