Permalink
Browse files

fix mrb_mod_cv_set and add test for Module#class_variable_set

  • Loading branch information...
1 parent d06512b commit f612f32aef65e5c1f16ebf50fcf9221309251d25 @skandhas skandhas committed Dec 21, 2012
Showing with 20 additions and 3 deletions.
  1. +5 −3 src/variable.c
  2. +15 −0 test/t/module.rb
View
8 src/variable.c
@@ -698,6 +698,8 @@ mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
void
mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v)
{
+ struct RClass * cls = c;
+
while (c) {
if (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)
c = c->super;
}
- if (!c->iv) {
- c->iv = iv_new(mrb);
+ if (!cls->iv) {
+ cls->iv = iv_new(mrb);
}
- iv_put(mrb, c->iv, sym, v);
+ iv_put(mrb, cls->iv, sym, v);
}
void
View
15 test/t/module.rb
@@ -54,6 +54,21 @@ class Test4ClassVariableGet
Test4ClassVariableGet.class_variable_get(:@@cv) == 99
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
class Test4ClassVariables1

0 comments on commit f612f32

Please sign in to comment.