Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 2.0 throws "[BUG] Stack consistency error"

Tags:

ruby

ruby-2.0

I'm following the exercises from Ruby Koans and in about_proxy_object_project.rb there's this bit of code:

class Proxy
  def initialize(target_object)
    @object = target_object
  end

  # This method was added by me
  def method_missing(method_name, *args, &block)
    @object.send method_name
  end
end

That gets called like this:

def test_tv_methods_still_perform_their_function
  tv = Proxy.new(Television.new) # Television is a class with a :channel attr_accessor and a power method

  tv.channel = 10
  tv.power

  assert_equal 10, tv.channel
  assert tv.on?
end

The problem is that the line tv.channel = 10 is "breaking" the interpreter and throwing:

[BUG] Stack consistency error (sp: 53, bp: 54)
ruby 2.0.0p0
(...)    
full stack trace follows

I've tried the same code with Ruby 1.9.3 and it's working. I'm using Ruby 2.0.0-p195.

So, is this an error/bug? Or I'm doing something horribly wrong?

like image 887
nicosantangelo Avatar asked Jul 07 '13 14:07

nicosantangelo


People also ask

What's an error in Ruby?

What’s an error in Ruby ? As Ruby is a fully object-oriented language, an error is an instance of a class that includes the Exception class in its ancestor chain irb> RuntimeError.ancestors.include?

How to handle exceptions in Ruby?

This can be done automatically by Ruby or manually. Catch and Throw is similar raise and rescue keywords, Exceptions can also be handled using catch and throw keywords in Ruby. Throw keyword generates an exception and whenever it is met, the program control goes to the catch statement.

What is the use of throw and catch in Ruby?

Catch and Throw is similar raise and rescue keywords, Exceptions can also be handled using catch and throw keywords in Ruby. Throw keyword generates an exception and whenever it is met, the program control goes to the catch statement. The catch block is used to jump out from the nested block and the block is labeled with a name.

Which method is in charge of raising errors in Ruby?

The Kernel#raise method is in charge of raising errors in Ruby In the first call to Kernel#raise, we can see that the method raises a RuntimeError — as no error class is explicitly specified as argument.


1 Answers

Yes. It is a Ruby bug in ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux]. At the end of the stack trace, it says:

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

You should report this to Ruby core. Please do so for the sake of the Ruby community.

As pointed out by matt, it is fixed in Ruby 2.0.0p247.

I don't see you doing anything wrong.

like image 95
sawa Avatar answered Oct 01 '22 01:10

sawa