mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
constant access should refer outer class/module; close #514
This commit is contained in:
+17
-1
@@ -700,7 +700,7 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym)
|
|||||||
}
|
}
|
||||||
c = c->super;
|
c = c->super;
|
||||||
}
|
}
|
||||||
if (!retry && base->tt == MRB_TT_MODULE) {
|
if (!retry && base && base->tt == MRB_TT_MODULE) {
|
||||||
c = mrb->object_class;
|
c = mrb->object_class;
|
||||||
retry = 1;
|
retry = 1;
|
||||||
goto L_RETRY;
|
goto L_RETRY;
|
||||||
@@ -733,6 +733,22 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
|
|||||||
struct RClass *c = mrb->ci->proc->target_class;
|
struct RClass *c = mrb->ci->proc->target_class;
|
||||||
|
|
||||||
if (!c) c = mrb->ci->target_class;
|
if (!c) c = mrb->ci->target_class;
|
||||||
|
if (c) {
|
||||||
|
struct RClass *c2 = c;
|
||||||
|
mrb_value v;
|
||||||
|
|
||||||
|
if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
c2 = c;
|
||||||
|
for (;;) {
|
||||||
|
c2 = mrb_class_outer_module(mrb, c2);
|
||||||
|
if (!c2) break;
|
||||||
|
if (c2->iv && iv_get(mrb, c2->iv, sym, &v)) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return const_get(mrb, c, sym);
|
return const_get(mrb, c, sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user