Skip to content

Thread::Backtrace::Location#base_label for blocks differs from MRI #5162

@ivoanjo

Description

@ivoanjo

Hello again!

I'm using Thread#backtrace_locations and noticed several differences between MRI and JRuby.

I'll report them separately because they may have different fixes, but feel free to mark any as duplicate if it makes sense to do so.


Environment

  • JRuby: jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
  • Kernel: Linux u186024434db159d25c92 4.13.0-39-generic #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Distro: Ubuntu 16.04.4 LTS

Expected Behavior

When looking at a Thread::Backtrace::Location, MRI provides both #base_label and #label.

For most methods, these are exactly the same, but for blocks it allows the caller to get the name of the method separate from the "block in" text without resorting to parsing the result.

Testcase:

puts RUBY_DESCRIPTION

def test
  [:test].map do
    location = Thread.current.backtrace_locations[1]
    puts "#base_label '#{location.base_label}', #label '#{location.label}'"
  end
end

test

Output on MRI:

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
#base_label 'test', #label 'block in test'

Actual Behavior

JRuby does not make such a distinction, and so base_label effectively becomes an alias of label:

jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
#base_label 'block in test', #label 'block in test'

If it would be helpful I can also submit a testcase to RubySpec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions