Commit f612f32a authored by skandhas's avatar skandhas

fix mrb_mod_cv_set and add test for Module#class_variable_set

parent d06512b0
...@@ -698,6 +698,8 @@ mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym) ...@@ -698,6 +698,8 @@ mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
void void
mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v) mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v)
{ {
struct RClass * cls = c;
while (c) { while (c) {
if (c->iv) { if (c->iv) {
iv_tbl *t = c->iv; iv_tbl *t = c->iv;
...@@ -710,11 +712,11 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v) ...@@ -710,11 +712,11 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v)
c = c->super; c = c->super;
} }
if (!c->iv) { if (!cls->iv) {
c->iv = iv_new(mrb); cls->iv = iv_new(mrb);
} }
iv_put(mrb, c->iv, sym, v); iv_put(mrb, cls->iv, sym, v);
} }
void void
......
...@@ -54,6 +54,21 @@ assert('Module#class_variable_get', '15.2.2.4.17') do ...@@ -54,6 +54,21 @@ assert('Module#class_variable_get', '15.2.2.4.17') do
Test4ClassVariableGet.class_variable_get(:@@cv) == 99 Test4ClassVariableGet.class_variable_get(:@@cv) == 99
end end
assert('Module#class_variable_set', '15.2.2.4.18') do
class Test4ClassVariableSet
@@foo = 100
def foo
@@foo
end
end
Test4ClassVariableSet.class_variable_set(:@@cv, 99)
Test4ClassVariableSet.class_variable_set(:@@foo, 101)
Test4ClassVariableSet.class_variables.include? :@@cv and
Test4ClassVariableSet.class_variable_get(:@@cv) == 99 and
Test4ClassVariableSet.new.foo == 101
end
assert('Module#class_variables', '15.2.2.4.19') do assert('Module#class_variables', '15.2.2.4.19') do
class Test4ClassVariables1 class Test4ClassVariables1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment