From 35784d10191308f39f694e8513cfc351d6712865 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 11 Jul 2012 20:11:45 +0000 Subject: [PATCH] defined: me in cfp * insns.def (defined): use method entry and id in cfp for proper superclass, since klass in iseq is shared by dynamically defined methods from the same block. [ruby-core:45831][Bug #6644] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 +++++++- insns.def | 15 +++++---------- test/ruby/test_defined.rb | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28a192f970..cfd442f753 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Jul 12 05:11:41 2012 Nobuyoshi Nakada + + * insns.def (defined): use method entry and id in cfp for proper + superclass, since klass in iseq is shared by dynamically defined + methods from the same block. [ruby-core:45831][Bug #6644] + Thu Jul 12 01:49:07 2012 NARUSE, Yui * lib/net/http.rb (Net::HTTP#connect): use local_host and local_port @@ -10,7 +16,7 @@ Wed Jul 11 17:36:39 2012 Nobuyoshi Nakada Wed Jul 11 12:38:20 2012 NAKAMURA Usaku - * ext/openssl/ossl_pkey_ec.c (ossl_ec_point_mul): nonstatic initializer + * ext/openssl/ossl_pkey_ec.c (ossl_ec_point_mul): nonstatic initializer of an aggregate type is a C99ism. * ext/openssl/ossl_pkey_ec.c (ossl_ec_point_mul): get rid of VC++ diff --git a/insns.def b/insns.def index ab40d30634..aa5b0eaf9f 100644 --- a/insns.def +++ b/insns.def @@ -826,16 +826,11 @@ defined } break; case DEFINED_ZSUPER:{ - rb_iseq_t *iseq = GET_ISEQ(); - while (iseq) { - if (iseq->defined_method_id) { - break; - } - iseq = iseq->parent_iseq; - } - if (iseq) { - VALUE klass = vm_search_normal_superclass(iseq->klass, GET_SELF()); - if (rb_method_boundp(klass, iseq->defined_method_id, 0)) { + const rb_method_entry_t *me = GET_CFP()->me; + if (me) { + VALUE klass = vm_search_normal_superclass(me->klass, GET_SELF()); + ID id = me->def ? me->def->original_id : me->called_id; + if (rb_method_boundp(klass, id, 0)) { expr_type = "super"; } } diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index 2552626b9e..99c866fc2d 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -136,4 +136,20 @@ class TestDefined < Test::Unit::TestCase bug5786 = '[ruby-dev:45021]' assert_nil(defined?(raise("[Bug#5786]")::A), bug5786) end + + def test_define_method + bug6644 = '[ruby-core:45831]' + a = Class.new do + def self.def_f!; + singleton_class.send(:define_method, :f) { defined? super } + end + end + aa = Class.new(a) + a.def_f! + assert_nil(a.f) + assert_nil(aa.f) + aa.def_f! + assert_equal("super", aa.f, bug6644) + assert_nil(a.f, bug6644) + end end