psyho / bogus

Fake library for Ruby
Other
359 stars 14 forks source link

Module#=== monkey patch breaks BasicObject#instance_eval on Rbx #61

Closed plexus closed 9 years ago

plexus commented 9 years ago

The monkey patch for Module#=== included in Bogus

class Module
  Bogus::Support.supress_warnings do
    def ===(object)
      object.kind_of?(self)
    end
  end
end

Breaks BasicObject#instance_eval on Rubinius.

class Foo < BasicObject
  def x
    3
  end
end

Foo.new.instance_eval do
  Kernel.puts x
end

# On MRI:
#
#      3
#
# On Rubinius:
#
# An exception occurred running /home/arne/projects/ruby-tmp/00205.rb:
#
#     Unable to send 'kind_of?' on instance of BasicObject (NoMethodError)
#
# Backtrace:
#
#   BasicObject(Foo)#kind_of? (method_missing) at kernel/common/basic_object.rb:3
#                                   Module#=== at /home/arne/projects/ruby-tmp/00205.rb:3
#               BasicObject(Foo)#instance_eval at kernel/common/eval.rb:24
#                            Object#__script__ at /home/arne/projects/ruby-tmp/00205.rb:13
#             Rubinius::CodeLoader#load_script at kernel/delta/code_loader.rb:66
#             Rubinius::CodeLoader.load_script at kernel/delta/code_loader.rb:152
#                      Rubinius::Loader#script at kernel/loader.rb:649
#                        Rubinius::Loader#main at kernel/loader.rb:825

This is because Rubinius's instance_eval calls Module#===

  def instance_eval(string=nil, filename="(eval)", line=1, &prc)
    if ::ImmediateValue === self
      sc = nil
    else
      sc = ::Rubinius::Type.object_singleton_class(self)
    end
    # ... snip
psyho commented 9 years ago

Thanks for reporting the issue. We override #kind_of? for fakes and we needed that monkey patch for MRI to acually use our implementation of #kind_of?. I'll check if we even need this monkey patch on Rubinious. If we do, then I'll try to come up with something that won't break instance_eval.

plexus commented 9 years ago

That sounds great! Thanks for the quick response :+1: