diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | bootstraptest/test_autoload.rb | 32 | ||||
-rw-r--r-- | load.c | 2 |
3 files changed, 40 insertions, 1 deletions
@@ -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 @@ -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"); } |