summaryrefslogtreecommitdiffhomepage
path: root/src/vm.c
diff options
context:
space:
mode:
authorKouhei Sutou <[email protected]>2014-08-09 15:06:17 +0900
committerKouhei Sutou <[email protected]>2014-08-09 15:06:17 +0900
commite75e2083fd6ddb35f58ac63ae2b98a5222b1854a (patch)
tree527c52dac48928d4c8744f2d1f1d268dd3cca6d1 /src/vm.c
parent39488f0baf879d474c70cface3dd056ff6912614 (diff)
downloadmruby-e75e2083fd6ddb35f58ac63ae2b98a5222b1854a.tar.gz
mruby-e75e2083fd6ddb35f58ac63ae2b98a5222b1854a.zip
Fix a bug that class variable can't be referenced from class method
Class method defined in singleton class should be evaluated in class context not singleton class context. fix #2515
Diffstat (limited to 'src/vm.c')
-rw-r--r--src/vm.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/vm.c b/src/vm.c
index 14388af9a..4b7a30d71 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2175,6 +2175,15 @@ RETRY_TRY_BLOCK:
}
else {
p = mrb_proc_new(mrb, irep->reps[GETARG_b(i)]);
+ if (c & OP_L_METHOD) {
+ if (p->target_class->tt == MRB_TT_SCLASS) {
+ mrb_value klass;
+ klass = mrb_obj_iv_get(mrb,
+ (struct RObject *)p->target_class,
+ mrb_intern_lit(mrb, "__attached__"));
+ p->target_class = mrb_class_ptr(klass);
+ }
+ }
}
if (c & OP_L_STRICT) p->flags |= MRB_PROC_STRICT;
regs[GETARG_A(i)] = mrb_obj_value(p);