From: Rolando Abarca Date: 2008-01-03T00:36:52+09:00 Subject: Re: bug? On Dec 31, 2007, at 11:54 PM, murphy wrote: > Rolando Abarca wrote: >> Doing some evals, I got this: > can you refactor it into a single file that fails? so we can reproduce > it and add it to knownbug, for example. > [murphy] ok, I got the problem, it was the eval'ed code: it was not catching an exception: #!/opt/ruby1.9/bin/ruby module M class A class A2 attr_accessor :at1, :at2 end class << self def workflow_rule obj = A2.new yield obj @arr ||= [] @arr << obj end def eval_str(str) begin eval(str, binding) rescue => err puts "something happened: #{err}" end end def eval_file(file) eval_str(File.read(file)) end end end end M::A.eval_str(DATA.read) __END__ workflow_rule do |r| r.at1 = "at1" r.at2 = "at2" r.at2 -> { puts "this shows a bug" } end The problem was that I forgot to put the assignment operator when setting an attribute to the instance "r", although this is an error, I think it should not raise a bug in ruby: {rolando@s-puck 12:33:50}$ /opt/ruby1.9/bin/ruby bug.rb (eval):4: [BUG] Stack consistency error (sp: 26, bp: 25) ruby 1.9.0 (2007-12-25 revision 14709) [i686-darwin9.1.0] -- control frame ---------- c:0009 p:0047 s:0026 b:0025 l:00087c d:001474 BLOCK (eval):4 c:0008 p:0020 s:0023 b:0023 l:000022 d:000022 METHOD bug.rb:12 c:0007 p:0007 s:0019 b:0019 l:00087c d:000a80 EVAL (eval):1 c:0006 p:---- s:0018 b:0018 l:000017 d:000017 FINISH :inherited c:0005 p:---- s:0016 b:0016 l:000015 d:000015 CFUNC :eval c:0004 p:0016 s:0011 b:0011 l:00087c d:00087c METHOD bug.rb:19 c:0003 p:0035 s:0006 b:0006 l:000005 d:000005 TOP bug.rb:32 c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH :inherited c:0001 p:0000 s:0002 b:0002 l:000001 d:000001 TOP : 37724 --------------------------- DBG> : "bug.rb:12:in `workflow_rule'" DBG> : "(eval):1:in `eval_str'" DBG> : "bug.rb:19:in `eval'" DBG> : "bug.rb:19:in `eval_str'" DBG> : "bug.rb:32:in `
'" -- backtrace of native function call (Use addr2line) -- 0xdb476 0x1b7dc 0x1b81b 0xd93ac 0xd9b0c 0x2511f 0x254a6 0xce555 0xd1900 0xd5794 0xd9b0c 0xd9dd9 0x1ec94 0x237fa 0x23cf 0x2336 ------------------------------------------------------- Abort trap {rolando@s-puck 12:33:52}$ ruby bug.rb something happened: wrong number of arguments (1 for 0) Notice that I changed the last line of the eval'ed code from -> to Proc.new, in order for the example to work with ruby 1.8. regards, -- Rolando Abarca Phone: +56-9 97851962 My Amazon Wish List: http://www.amazon.com/gp/registry/wishlist/3AGJOT5E6SIQB