Skip to content

Commit 872517d

Browse files
committed
class variables in higher order have a priority; fix #3235
1 parent 1142cf2 commit 872517d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/variable.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -760,26 +760,30 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym)
760760
{
761761
struct RClass * cls = c;
762762
mrb_value v;
763+
int given = FALSE;
763764

764765
while (c) {
765766
if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
766-
return v;
767+
given = TRUE;
767768
}
768769
c = c->super;
769770
}
771+
if (given) return v;
770772
if (cls && cls->tt == MRB_TT_SCLASS) {
771773
mrb_value klass;
772774

773775
klass = mrb_obj_iv_get(mrb, (struct RObject *)cls,
774776
mrb_intern_lit(mrb, "__attached__"));
775777
c = mrb_class_ptr(klass);
776778
if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) {
779+
given = FALSE;
777780
while (c) {
778781
if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
779-
return v;
782+
given = TRUE;
780783
}
781784
c = c->super;
782785
}
786+
if (given) return v;
783787
}
784788
}
785789
mrb_name_error(mrb, sym, "uninitialized class variable %S in %S",

0 commit comments

Comments
 (0)