ruby-changes:24318
From: nobu <ko1@a...>
Date: Thu, 12 Jul 2012 05:12:02 +0900 (JST)
Subject: [ruby-changes:24318] nobu:r36369 (trunk): defined: me in cfp
nobu 2012-07-12 05:11:45 +0900 (Thu, 12 Jul 2012) New Revision: 36369 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36369 Log: 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] Modified files: trunk/ChangeLog trunk/insns.def trunk/test/ruby/test_defined.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 36368) +++ ChangeLog (revision 36369) @@ -1,3 +1,9 @@ +Thu Jul 12 05:11:41 2012 Nobuyoshi Nakada <nobu@r...> + + * 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 <naruse@r...> * lib/net/http.rb (Net::HTTP#connect): use local_host and local_port @@ -10,7 +16,7 @@ Wed Jul 11 12:38:20 2012 NAKAMURA Usaku <usa@r...> - * 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++ Index: insns.def =================================================================== --- insns.def (revision 36368) +++ insns.def (revision 36369) @@ -826,16 +826,11 @@ } 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"; } } Index: test/ruby/test_defined.rb =================================================================== --- test/ruby/test_defined.rb (revision 36368) +++ test/ruby/test_defined.rb (revision 36369) @@ -136,4 +136,20 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/