From 303cd88d408b7f8b79b0580cf3d552d6e291f5df Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 9 Dec 2015 07:15:48 +0000 Subject: [PATCH] * vm.c (rb_vm_cref_in_context): Module#define_method in non-class expression should be public. [Bug #11754] * test/ruby/test_method.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ test/ruby/test_method.rb | 4 +++- vm.c | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1c44cd8c00..6e200e97d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Dec 9 16:10:37 2015 Koichi Sasada + + * vm.c (rb_vm_cref_in_context): Module#define_method in non-class + expression should be public. + [Bug #11754] + + * test/ruby/test_method.rb: add a test. + Wed Dec 9 15:48:12 2015 Nobuyoshi Nakada * regcomp.c (onig_chain_link_add): use atomic operation instead of diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 9e20d5cc22..48178c4d7a 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -924,6 +924,8 @@ class TestMethod < Test::Unit::TestCase def m1 def m2 end + + self.class.send(:define_method, :m3){} # [Bug #11754] end private end @@ -933,7 +935,7 @@ class TestMethod < Test::Unit::TestCase assert_equal([].sort, MethodInMethodClass.private_instance_methods(false).sort) MethodInMethodClass.new.m1 - assert_equal([:m1, :m2].sort, MethodInMethodClass.public_instance_methods(false).sort) + assert_equal([:m1, :m2, :m3].sort, MethodInMethodClass.public_instance_methods(false).sort) assert_equal([].sort, MethodInMethodClass.private_instance_methods(false).sort) end end diff --git a/vm.c b/vm.c index 23be295fef..b83595db36 100644 --- a/vm.c +++ b/vm.c @@ -1226,6 +1226,7 @@ rb_vm_cref_in_context(VALUE self, VALUE cbase) const rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp); const rb_cref_t *cref; if (cfp->self != self) return NULL; + if (!vm_env_cref_by_cref(cfp->ep)) return NULL; cref = rb_vm_get_cref(cfp->ep); if (CREF_CLASS(cref) != cbase) return NULL; return cref;