* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2011-07-10 06:32:06 +00:00
parent 8c812c9a03
commit 564fb6a795
3 changed files with 40 additions and 1 deletions

View File

@ -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

View File

@ -1,3 +1,35 @@
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"

2
load.c
View File

@ -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");
}