summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_autoload.rb18
-rw-r--r--variable.c5
3 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 898a62131d..10ea1992cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Apr 14 21:23:29 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * variable.c (rb_autoload_p): search superclasses as same as actual
+ loading. fixes [ruby-core:35679]
+
Thu Apr 14 21:21:06 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/win32.h (frexp, modf): wrongly declared as pure in
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb
index f1a72fa11a..dd049f047a 100644
--- a/test/ruby/test_autoload.rb
+++ b/test/ruby/test_autoload.rb
@@ -34,4 +34,22 @@ p Foo::Bar
File.unlink(*tmpfiles) rescue nil if tmpfiles
tmpdirs.each {|dir| Dir.rmdir(dir)}
end
+
+ def test_autoload_p
+ bug4565 = '[ruby-core:35679]'
+
+ require 'tmpdir'
+ tmpdir = Dir.mktmpdir('autoload')
+ tmpfile = tmpdir + '/foo.rb'
+ a = Module.new do
+ autoload :X, tmpfile
+ end
+ b = Module.new do
+ include a
+ end
+ assert_equal(true, a.const_defined?(:X))
+ assert_equal(true, b.const_defined?(:X))
+ assert_equal(tmpfile, a.autoload?(:X), bug4565)
+ assert_equal(tmpfile, b.autoload?(:X), bug4565)
+ end
end
diff --git a/variable.c b/variable.c
index 7f813ad6d4..3c9fe7175e 100644
--- a/variable.c
+++ b/variable.c
@@ -1569,7 +1569,10 @@ rb_autoload_p(VALUE mod, ID id)
NODE *load;
const char *loading = 0;
- if (!autoload_node_id(mod, id)) return Qnil;
+ while (!autoload_node_id(mod, id)) {
+ mod = RCLASS_SUPER(mod);
+ if (!mod) return Qnil;
+ }
load = autoload_node(mod, id, &loading);
if (!load) return Qnil;
return load && (file = load->nd_lit) ? file : Qnil;