ruby-changes:23003
From: nobu <ko1@a...>
Date: Fri, 16 Mar 2012 12:00:55 +0900 (JST)
Subject: [ruby-changes:23003] nobu:r35052 (trunk): * vm_insnhelper.c (argument_error): use line number at the beginning
nobu 2012-03-16 12:00:44 +0900 (Fri, 16 Mar 2012) New Revision: 35052 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35052 Log: * vm_insnhelper.c (argument_error): use line number at the beginning of lambda, not the first code ob its body. [ruby-core:43314][Bug #6151] Modified files: trunk/ChangeLog trunk/test/ruby/test_lambda.rb trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 35051) +++ ChangeLog (revision 35052) @@ -1,5 +1,9 @@ -Fri Mar 16 11:59:56 2012 Nobuyoshi Nakada <nobu@r...> +Fri Mar 16 12:00:42 2012 Nobuyoshi Nakada <nobu@r...> + * vm_insnhelper.c (argument_error): use line number at the beginning + of lambda, not the first code ob its body. + [ruby-core:43314][Bug #6151] + * iseq.c (rb_iseq_first_lineno): constified. Fri Mar 16 11:20:07 2012 Shugo Maeda <shugo@r...> Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 35051) +++ vm_insnhelper.c (revision 35052) @@ -130,12 +130,8 @@ VALUE err_line = 0; if (iseq) { - int line_no = 1; + int line_no = rb_iseq_first_lineno(iseq); - if (iseq->line_info_size) { - line_no = iseq->line_info_table[0].line_no; - } - err_line = rb_sprintf("%s:%d:in `%s'", RSTRING_PTR(iseq->filename), line_no, RSTRING_PTR(iseq->name)); Index: test/ruby/test_lambda.rb =================================================================== --- test/ruby/test_lambda.rb (revision 35051) +++ test/ruby/test_lambda.rb (revision 35052) @@ -70,4 +70,23 @@ BasicObject.new.instance_eval {->() {called = true}.()} assert_equal(true, called, bug5966) end + + def test_location_on_error + bug6151 = '[ruby-core:43314]' + called = 0 + line, f = __LINE__, lambda do + called += 1 + true + end + e = assert_raise(ArgumentError) do + f.call(42) + end + assert_send([e.backtrace.first, :start_with?, "#{__FILE__}:#{line}:"], bug6151) + assert_equal(0, called) + e = assert_raise(ArgumentError) do + 42.times(&f) + end + assert_send([e.backtrace.first, :start_with?, "#{__FILE__}:#{line}:"], bug6151) + assert_equal(0, called) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/