Commit ad492eb9 authored by Kouhei Sutou's avatar Kouhei Sutou

Fix class variable reference in module

Fix #3079
parent e132de9e
...@@ -773,7 +773,7 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym) ...@@ -773,7 +773,7 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym)
klass = mrb_obj_iv_get(mrb, (struct RObject *)cls, klass = mrb_obj_iv_get(mrb, (struct RObject *)cls,
mrb_intern_lit(mrb, "__attached__")); mrb_intern_lit(mrb, "__attached__"));
c = mrb_class_ptr(klass); c = mrb_class_ptr(klass);
if (c->tt == MRB_TT_CLASS) { if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) {
while (c) { while (c) {
if (c->iv && iv_get(mrb, c->iv, sym, &v)) { if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
return v; return v;
......
...@@ -384,6 +384,19 @@ assert('class variable and class << self style class method') do ...@@ -384,6 +384,19 @@ assert('class variable and class << self style class method') do
assert_equal("value", ClassVariableTest.class_variable) assert_equal("value", ClassVariableTest.class_variable)
end end
assert('class variable in module and class << self style class method') do
module ClassVariableInModuleTest
@@class_variable = "value"
class << self
def class_variable
@@class_variable
end
end
end
assert_equal("value", ClassVariableInModuleTest.class_variable)
end
assert('class with non-class/module outer raises TypeError') do assert('class with non-class/module outer raises TypeError') do
assert_raise(TypeError) { class 0::C1; end } assert_raise(TypeError) { class 0::C1; end }
assert_raise(TypeError) { class []::C2; end } assert_raise(TypeError) { class []::C2; end }
......
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