Commit 9eb2ed08 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #3571 from keizo042/fix_get_constant_of_module_from_sigleton

Modify to get constant of parent module in singleton class; fix #3568
parents 39ca4ef3 507e00e8
...@@ -949,7 +949,7 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym) ...@@ -949,7 +949,7 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
klass = mrb_obj_iv_get(mrb, (struct RObject *)c, klass = mrb_obj_iv_get(mrb, (struct RObject *)c,
mrb_intern_lit(mrb, "__attached__")); mrb_intern_lit(mrb, "__attached__"));
c2 = mrb_class_ptr(klass); c2 = mrb_class_ptr(klass);
if (c2->tt == MRB_TT_CLASS) if (c2->tt == MRB_TT_CLASS || c2->tt == MRB_TT_MODULE)
c = c2; c = c2;
} }
c2 = c; c2 = c;
......
...@@ -849,3 +849,14 @@ assert('module with non-class/module outer raises TypeError') do ...@@ -849,3 +849,14 @@ assert('module with non-class/module outer raises TypeError') do
assert_raise(TypeError) { module 0::M1 end } assert_raise(TypeError) { module 0::M1 end }
assert_raise(TypeError) { module []::M2 end } assert_raise(TypeError) { module []::M2 end }
end end
assert('get constant of parent module in singleton class; issue #3568') do
actual = module GetConstantInSingletonTest
EXPECTED = "value"
class << self
EXPECTED
end
end
assert_equal("value", actual)
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