diff options
-rw-r--r-- | proc.c | 18 | ||||
-rw-r--r-- | test/ruby/test_method.rb | 13 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 24 insertions, 9 deletions
@@ -1769,21 +1769,23 @@ VALUE rb_obj_singleton_method(VALUE obj, VALUE vid) { const rb_method_entry_t *me; - VALUE klass; + VALUE klass = rb_singleton_class_get(obj); ID id = rb_check_id(&vid); + if (NIL_P(klass) || NIL_P(klass = RCLASS_ORIGIN(klass))) { + undef: + rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", + obj, vid); + } if (!id) { - if (!NIL_P(klass = rb_singleton_class_get(obj)) && - respond_to_missing_p(klass, obj, vid, FALSE)) { + if (respond_to_missing_p(klass, obj, vid, FALSE)) { id = rb_intern_str(vid); return mnew_missing(klass, obj, id, rb_cMethod); } - undef: - rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", - obj, vid); + goto undef; } - if (NIL_P(klass = rb_singleton_class_get(obj)) || - UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) || + me = rb_method_entry_at(klass, id); + if (UNDEFINED_METHOD_ENTRY_P(me) || UNDEFINED_REFINED_METHOD_P(me->def)) { vid = ID2SYM(id); goto undef; diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 0ef913fd78..fe0171dd57 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -782,6 +782,19 @@ class TestMethod < Test::Unit::TestCase assert_equal(:bar, m.call, feature8391) end + def test_singleton_method_prepend + bug14658 = '[Bug #14658]' + c1 = Class.new + o = c1.new + def o.bar; :bar; end + class << o; prepend Module.new; end + m = assert_nothing_raised(NameError, bug14658) {o.singleton_method(:bar)} + assert_equal(:bar, m.call, bug14658) + + o = Object.new + assert_raise(NameError, bug14658) {o.singleton_method(:bar)} + end + Feature9783 = '[ruby-core:62212] [Feature #9783]' def assert_curry_three_args(m) @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.5.2" #define RUBY_RELEASE_DATE "2018-10-09" -#define RUBY_PATCHLEVEL 94 +#define RUBY_PATCHLEVEL 95 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 10 |