diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-19 15:48:04 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-20 13:07:58 +0900 |
| commit | 15701a32f5a58471ce02d25cb5fbada81cd9da2c (patch) | |
| tree | f05b1b8448e4421d494ab0da62d092e5aca15284 /src | |
| parent | 683baec4f0249d1677863ced20a7921734e6faed (diff) | |
| download | mruby-15701a32f5a58471ce02d25cb5fbada81cd9da2c.tar.gz mruby-15701a32f5a58471ce02d25cb5fbada81cd9da2c.zip | |
Fix compatibility issue of class variables.
Singleton class definition do not introduce its own class variable scope
in CRuby/JRuby. So should mruby.
```
module Mod1
class << Object.new
C = 1
@@cv = 1
p Module.nesting, # => [#<Class:#<Object:0x55cb16e60a50>>, Mod1]
constants, # => [:C]
class_variables, # => []
Mod1.class_variables # => [:@@cv]
end
end
```
Diffstat (limited to 'src')
| -rw-r--r-- | src/variable.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/variable.c b/src/variable.c index cb06a8341..62d6f35a5 100644 --- a/src/variable.c +++ b/src/variable.c @@ -743,7 +743,13 @@ mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym) { struct RClass *c; - c = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc); + struct RProc *p = mrb->c->ci->proc; + + for (;;) { + c = MRB_PROC_TARGET_CLASS(p); + if (c->tt != MRB_TT_SCLASS) break; + p = p->upper; + } return mrb_mod_cv_get(mrb, c, sym); } @@ -751,8 +757,13 @@ void mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { struct RClass *c; + struct RProc *p = mrb->c->ci->proc; - c = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc); + for (;;) { + c = MRB_PROC_TARGET_CLASS(p); + if (c->tt != MRB_TT_SCLASS) break; + p = p->upper; + } mrb_mod_cv_set(mrb, c, sym, v); } |
