From 3b7373fd00a0ba456498a7b7d6de2a47c96434a2 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 9 Nov 2017 05:22:51 +0000 Subject: fix backtrace on argment error. * vm_backtrace.c (rb_backtrace_use_iseq_first_lineno_for_last_location): added. It modifies last location's line as corresponding iseq's first line number. * vm_args.c (raise_argument_error): use added function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_method.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/ruby/test_method.rb') diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index ce67aada2b..778fcdc9bc 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -990,4 +990,31 @@ class TestMethod < Test::Unit::TestCase assert_equal('1', obj.foo(1)) assert_equal('1', obj.bar(1)) end + + def test_argument_error_location + body = <<-'END_OF_BODY' + eval <<-'EOS' + $line_lambda = __LINE__; $f = lambda do + _x = 1 + end + $line_method = __LINE__; def foo + _x = 1 + end + begin + $f.call(1) + rescue ArgumentError => e + assert_equal "(eval):#{$line_lambda.to_s}:in `block in
'", e.backtrace.first + end + begin + foo(1) + rescue ArgumentError => e + assert_equal "(eval):#{$line_method}:in `foo'", e.backtrace.first + end + EOS + END_OF_BODY + + assert_separately [], body + # without trace insn + assert_separately [], "RubyVM::InstructionSequence.compile_option = {trace_instruction: false}\n" + body + end end -- cgit v1.2.3