Skip to content

Line numbers in backtrace with multiline method invocation are sometimes different from CRuby (again) #4737

@yujinakayama

Description

@yujinakayama

This is similar to #4664.

As @enebo said in #4664 (comment):

I corrected this for fcall nodes but I imagine other cases exist. This at least fixes the reported issue...

... it seems this is another case.


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

puts "RUBY_ENGINE: #{RUBY_ENGINE}"
puts "RUBY_VERSION: #{RUBY_VERSION}"
puts "JRUBY_VERSION: #{JRUBY_VERSION}" if defined?(JRUBY_VERSION)
puts '=' * 40

def expect(*)
  Expectation.new
end

class Expectation
  def to(matcher)
    raise
  end
end

class Matcher
  def and(matcher)
  end
end

begin
  expect('something').to Matcher.new # Line 22
                    .and Matcher.new # Line 23
rescue => error
  puts error.backtrace
end

... JRuby reports the following backtrace:

RUBY_ENGINE: jruby
RUBY_VERSION: 2.3.3
JRUBY_VERSION: 9.1.12.0
========================================
test.rb:12:in `to'
test.rb:23:in `<main>'

... in contrast to CRuby:

RUBY_ENGINE: ruby
RUBY_VERSION: 2.4.1
========================================
test.rb:12:in `to'
test.rb:22:in `<main>'

Environment

$ jruby -v
jruby 9.1.12.0 (2.3.3) 2017-06-15 33c6439 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.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

Expected Behavior

With the above script, backtrace should include the beginning line number of the method invocation (the expect('something').to Matcher.new line) as CRuby does.

Actual Behavior

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions