diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index d781831..755d5e2 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -449,5 +449,49 @@ class TestMarshal < Test::Unit::TestCase o2 = Marshal.load(m) assert_equal(o1, o2) end - + + class MyThing + @defines = [] + @missings = [] + @consts = [] + class << self; + attr_accessor :defines + attr_accessor :missings + attr_accessor :consts + end + + def self.const_defined? sym + @defines << sym + true + end + + def self.const_missing sym + @missings << sym + class_eval consts.pop + const_get sym + end + end + + def test_call_const_defined? + foo_definition = <<-eorb + class Foo + attr_reader :message + def initialize message + @message = message + end + end + eorb + MyThing.class_eval foo_definition + str = Marshal.dump MyThing::Foo.new 'bara' + assert_equal [:Foo], MyThing.defines + + MyThing.send(:remove_const, :Foo) + MyThing.consts << foo_definition + obj = Marshal.load(str) + assert_instance_of MyThing::Foo, obj + assert_equal 'bara', obj.message + + assert_equal [:Foo, :Foo], MyThing.defines + assert_equal [:Foo], MyThing.missings + end end diff --git a/variable.c b/variable.c index 382644b..61802ca 100644 --- a/variable.c +++ b/variable.c @@ -272,7 +272,7 @@ rb_path_to_class(VALUE pathname) p += 2; pbeg = p; } - if (!rb_const_defined(c, id)) { + if (!rb_funcall(c, rb_intern("const_defined?"), 1, ID2SYM(id))) { undefined_class: rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path); }