Skip to content

Commit

Permalink
Modify to get constant of parent module in singleton class; fix #3568
Browse files Browse the repository at this point in the history
  • Loading branch information
keizo042 authored and Kouichi Nakanishi committed Mar 31, 2017
1 parent 952207d commit 507e00e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
klass = mrb_obj_iv_get(mrb, (struct RObject *)c,
mrb_intern_lit(mrb, "__attached__"));
c2 = mrb_class_ptr(klass);
if (c2->tt == MRB_TT_CLASS)
if (c2->tt == MRB_TT_CLASS || c2->tt == MRB_TT_MODULE)
c = c2;
}
c2 = c;
Expand Down
11 changes: 11 additions & 0 deletions test/t/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -849,3 +849,14 @@ def modfunc; end
assert_raise(TypeError) { module 0::M1 end }
assert_raise(TypeError) { module []::M2 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

0 comments on commit 507e00e

Please sign in to comment.