New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line numbers in backtrace with multiline method invocation are sometimes different from CRuby #4664

Closed
yujinakayama opened this Issue Jun 10, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@yujinakayama

When there's a method invocation with multiline method invocation as an argument:

def do_something(*)
  raise
end

begin
  do_something(Object # Line 6
               .new)  # Line 7
rescue => error
  puts error.backtrace
end

... JRuby reports the following backtrace:

test.rb:2:in `do_something'
test.rb:7:in `<main>'

... in contrast to CRuby:

test.rb:2:in `do_something'
test.rb:6:in `<main>'

Environment

$ jruby -v
jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a Java HotSpot(TM) 64-Bit Server VM 25.25-b02 on 1.8.0_25-b17 +jit [darwin-x86_64]
$ uname -a
Darwin macbookpro.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

Expected Behavior

With the following script:

def do_something(*)
  raise
end

def print_error_line(error)
  line_number = error.backtrace[1].split(':')[1].to_i
  p File.read(__FILE__).lines[line_number - 1]
end

puts "RUBY_ENGINE: #{RUBY_ENGINE}"
puts "RUBY_VERSION: #{RUBY_VERSION}"
puts "JRUBY_VERSION: #{JRUBY_VERSION}" if defined?(JRUBY_VERSION)

begin
  do_something(Object
               .new)
rescue => error
  puts '=' * 40
  puts error.backtrace
  print_error_line(error)
end

Backtrace should include the beginning line number of the method invocation (the do_something line), as CRuby does:

$ ruby test.rb
RUBY_ENGINE: ruby
RUBY_VERSION: 2.4.1
========================================
test.rb:2:in `do_something'
test.rb:15:in `<main>'
"  do_something(Object\n"

Actual Behavior

JRuby 9.1.10.0 reports backtrace including the last line number of the method invocation (the .new) line):

$ ruby test.rb
RUBY_ENGINE: jruby
RUBY_VERSION: 2.3.3
JRUBY_VERSION: 9.1.10.0
========================================
test.rb:2:in `do_something'
test.rb:16:in `<main>'
"               .new)\n"

@enebo enebo added the parser label Jun 12, 2017

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Jun 12, 2017

Member

Most interestingly (for me) is that the AST is correct:

        FCallNode:do_something 5
          ArrayNode 5
            CallNode:new 6
              ConstNode:Object 6

If I look at the IR I can see one line_num 6 (which will display 7) combing from the Object.new but no line_num 5 after the .new call.

Member

enebo commented Jun 12, 2017

Most interestingly (for me) is that the AST is correct:

        FCallNode:do_something 5
          ArrayNode 5
            CallNode:new 6
              ConstNode:Object 6

If I look at the IR I can see one line_num 6 (which will display 7) combing from the Object.new but no line_num 5 after the .new call.

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Jun 12, 2017

Member

Fixed in commit d7d063d. I accidentally referred to the wrong commit number and since I pushed it I do not want to ammend.

There is a general issue in our IRBuilder where a parent level node when built will indicate that it is a newline node and that it changes the line number....but it has children which also are newline nodes which want to change the line number. So the parent line_num instr is ommitted. I corrected this for fcall nodes but I imagine other cases exist. This at least fixes the reported issue...

Member

enebo commented Jun 12, 2017

Fixed in commit d7d063d. I accidentally referred to the wrong commit number and since I pushed it I do not want to ammend.

There is a general issue in our IRBuilder where a parent level node when built will indicate that it is a newline node and that it changes the line number....but it has children which also are newline nodes which want to change the line number. So the parent line_num instr is ommitted. I corrected this for fcall nodes but I imagine other cases exist. This at least fixes the reported issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment