From d3326ddf1113a0b0788658e5ef6131f2722ab3c4 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 24 Mar 2011 14:06:31 +0000 Subject: [PATCH] * vm_insnhelper.c (vm_get_ev_const): should not autoload in defined? mode. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- test/ruby/test_defined.rb | 11 +++++++++++ vm_insnhelper.c | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1472f90787..425cb9e8bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Thu Mar 24 23:05:42 2011 Nobuyoshi Nakada +Thu Mar 24 23:06:29 2011 Nobuyoshi Nakada + + * vm_insnhelper.c (vm_get_ev_const): should not autoload in + defined? mode. * variable.c (rb_const_defined_0): fix autoloading base. [ruby-core:35509] diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index e1d685275d..6a1f702648 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -103,4 +103,15 @@ class TestDefined < Test::Unit::TestCase end assert_equal("constant", klass.new.a?, bug) end + + def test_autoloaded_noload + klass = Class.new do + autoload(:A, "a") + def a? + defined?(A) + end + end + x = klass.new + assert_equal("constant", x.a?) + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 3666aed53e..00a21e3669 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1177,6 +1177,7 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq, if (val == Qundef) { if (am == klass) break; am = klass; + if (is_defined) return 1; rb_autoload_load(klass, id); goto search_continue; }