summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--bootstraptest/test_autoload.rb32
-rw-r--r--load.c2
3 files changed, 40 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c64fe8480..1d122fdbdb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sun Jul 10 15:30:00 2011 Kenta Murata <mrkn@mrkn.jp>
+
+ * load.c (rb_f_autoload): prevent to autoload for singleton
+ classes. fixes [Bug #4886] [ruby-dev:43816]
+
+ * bootstraptest/test_autoload.rb: add tests for the above change.
+
Sun Jul 10 15:09:17 2011 Shota Fukumori <sorah@tubusu.net>
* lib/test/unit/assertions.rb: Import documentation patch by Justin
diff --git a/bootstraptest/test_autoload.rb b/bootstraptest/test_autoload.rb
index b781fdb7e9..e8df6684b6 100644
--- a/bootstraptest/test_autoload.rb
+++ b/bootstraptest/test_autoload.rb
@@ -1,4 +1,36 @@
assert_equal 'ok', %q{
+ File.unlink('zzz.rb') if File.file?('zzz.rb')
+ instance_eval do
+ autoload :ZZZ, './zzz.rb'
+ begin
+ ZZZ
+ rescue LoadError
+ :ok
+ end
+ end
+}, '[ruby-dev:43816]'
+
+assert_equal 'ok', %q{
+ open('zzz.rb', 'w') {|f| f.puts '' }
+ instance_eval do
+ autoload :ZZZ, './zzz.rb'
+ begin
+ ZZZ
+ rescue NameError
+ :ok
+ end
+ end
+}, '[ruby-dev:43816]'
+
+assert_equal 'ok', %q{
+ open('zzz.rb', 'w') {|f| f.puts 'class ZZZ; def self.ok;:ok;end;end'}
+ instance_eval do
+ autoload :ZZZ, './zzz.rb'
+ ZZZ.ok
+ end
+}, '[ruby-dev:43816]'
+
+assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
autoload :ZZZ, "./zzz.rb"
ZZZ.ok
diff --git a/load.c b/load.c
index b819bf37f9..62e2cac4c6 100644
--- a/load.c
+++ b/load.c
@@ -722,7 +722,7 @@ rb_mod_autoload_p(VALUE mod, VALUE sym)
static VALUE
rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
{
- VALUE klass = rb_vm_cbase();
+ VALUE klass = rb_class_real(rb_vm_cbase());
if (NIL_P(klass)) {
rb_raise(rb_eTypeError, "Can not set autoload on singleton class");
}