diff options
| author | Kouichi Nakanishi <[email protected]> | 2017-03-31 12:55:43 +0900 |
|---|---|---|
| committer | Kouichi Nakanishi <[email protected]> | 2017-03-31 13:43:20 +0900 |
| commit | 507e00e86f73787560ddedb7e7b875a6d5ed37a4 (patch) | |
| tree | 6e315f74dc24f92db9e2ae129f3babb4e476b297 | |
| parent | 952207d2433d2de1443c791ec1932c05dbd53be8 (diff) | |
| download | mruby-507e00e86f73787560ddedb7e7b875a6d5ed37a4.tar.gz mruby-507e00e86f73787560ddedb7e7b875a6d5ed37a4.zip | |
Modify to get constant of parent module in singleton class; fix #3568
| -rw-r--r-- | src/variable.c | 2 | ||||
| -rw-r--r-- | test/t/module.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/variable.c b/src/variable.c index c98008af7..f130a968f 100644 --- a/src/variable.c +++ b/src/variable.c @@ -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; diff --git a/test/t/module.rb b/test/t/module.rb index 6b0632414..cfdca8503 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -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 []::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 |
