summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_method.rb19
-rw-r--r--vm_insnhelper.c5
3 files changed, 28 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 7c039617f9..7b732baf62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Dec 3 12:17:19 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * vm_insnhelper.c (vm_call_method): protected singleton methods should
+ be visible from same real class methods. [ruby-core:33506]
+
Fri Dec 3 07:08:42 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_getline): round upto next char
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index da17ef5e9c..2f3ba3ebd6 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -411,4 +411,23 @@ class TestMethod < Test::Unit::TestCase
assert_nothing_raised { v.instance_eval { mv2 } }
assert_nothing_raised { v.instance_eval { mv3 } }
end
+
+ def test_protected_singleton
+ bug4106 = '[ruby-core:33506]'
+ a = Class.new do
+ def meth
+ :called
+ end
+ def test
+ a = dup
+ class << a
+ protected :meth
+ end
+ a.meth
+ end
+ end.new
+ called = nil
+ assert_nothing_raised(NoMethodError, bug4106) {called = a.test}
+ assert_equal(:called, called, bug4106)
+ end
end
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 18c22cb81d..6ec6026e37 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -629,7 +629,10 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp,
else if (!(flag & VM_CALL_OPT_SEND_BIT) && (me->flag & NOEX_MASK) & NOEX_PROTECTED) {
VALUE defined_class = me->klass;
- if (TYPE(defined_class) == T_ICLASS) {
+ if (FL_TEST(defined_class, FL_SINGLETON)) {
+ defined_class = RCLASS_SUPER(defined_class);
+ }
+ else if (RB_TYPE_P(defined_class, T_ICLASS)) {
defined_class = RBASIC(defined_class)->klass;
}