summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorskandhas <[email protected]>2012-12-21 16:17:13 +0800
committerskandhas <[email protected]>2012-12-21 16:17:13 +0800
commitf612f32aef65e5c1f16ebf50fcf9221309251d25 (patch)
tree4b0c7f1badda57591a6b68ff04ea419b519dcfa2
parentd06512b093ebbbedb9affad263f4fd2e369166d0 (diff)
downloadmruby-f612f32aef65e5c1f16ebf50fcf9221309251d25.tar.gz
mruby-f612f32aef65e5c1f16ebf50fcf9221309251d25.zip
fix mrb_mod_cv_set and add test for Module#class_variable_set
-rw-r--r--src/variable.c8
-rw-r--r--test/t/module.rb15
2 files changed, 20 insertions, 3 deletions
diff --git a/src/variable.c b/src/variable.c
index 57a193109..7743c6309 100644
--- a/src/variable.c
+++ b/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
diff --git a/test/t/module.rb b/test/t/module.rb
index fbc93eb08..54d4f3015 100644
--- a/test/t/module.rb
+++ b/test/t/module.rb
@@ -54,6 +54,21 @@ assert('Module#class_variable_get', '15.2.2.4.17') do
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