summaryrefslogtreecommitdiffhomepage
path: root/src/variable.c
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-11-01 04:21:39 +0900
committerYukihiro Matsumoto <[email protected]>2012-11-01 04:21:39 +0900
commit8cf42709d1933ad450120dff145723acba1fbc68 (patch)
treec040db06a9ff7c7c4efe8437f0a41ffcfd39b2e0 /src/variable.c
parentb720156c99eb974b13492873579239697ebcaf96 (diff)
downloadmruby-8cf42709d1933ad450120dff145723acba1fbc68.tar.gz
mruby-8cf42709d1933ad450120dff145723acba1fbc68.zip
constant access should refer outer class/module; close #514
Diffstat (limited to 'src/variable.c')
-rw-r--r--src/variable.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/variable.c b/src/variable.c
index af75f5169..eebe81575 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -700,7 +700,7 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym)
}
c = c->super;
}
- if (!retry && base->tt == MRB_TT_MODULE) {
+ if (!retry && base && base->tt == MRB_TT_MODULE) {
c = mrb->object_class;
retry = 1;
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;
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);
}