Project

General

Profile

Actions

Bug #21816

open

iseq code_location of proc changed

Bug #21816: iseq code_location of proc changed

Added by zzak (zzak _) about 5 hours ago. Updated about 4 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:124408]

Description

TBH, I'm not really sure if that title matches the problem here, but I can produce this issue with the following test:

# bug.rb

# note the indentation of the callable
  callable = -> { puts "Hello, World!" }

iseq = RubyVM::InstructionSequence.of(callable)

pp iseq.to_a
pp iseq.to_a[4]

pp iseq.to_a[4][:code_location][1]

Ruby 4.0.0:

$ ruby -v bug.rb
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [x86_64-linux]
["YARVInstructionSequence/SimpleDataFormat",
 4,
 0,
 1,
 {arg_size: 0, local_size: 0, stack_max: 2, node_id: 7, code_location: [1, 15, 1, 40], node_ids: [4, 5, 4, 7], parser: :prism},
 "block in <main>",
 "bug.rb",
 "/tmp/tmp.Fbq5WA0GnO/bug.rb",
 1,
 :block,
 [],
 {},
 [],
 [1,
  :RUBY_EVENT_LINE,
  :RUBY_EVENT_B_CALL,
  [:putself],
  [:putchilledstring, "Hello, World!"],
  [:opt_send_without_block, {mid: :puts, flag: 20, orig_argc: 1}],
  :RUBY_EVENT_B_RETURN,
  [:leave]]]
{arg_size: 0, local_size: 0, stack_max: 2, node_id: 7, code_location: [1, 15, 1, 40], node_ids: [4, 5, 4, 7], parser: :prism}
15

Ruby 4.1.0:

$ ruby -v bug.rb
ruby 4.1.0dev (2025-12-30T18:02:00Z master 9d37155cfc) +PRISM [x86_64-linux]
["YARVInstructionSequence/SimpleDataFormat",
 4,
 1,
 1,
 {arg_size: 0,
  local_size: 0,
  stack_max: 2,
  node_id: 7,
  code_location: [1, 13, 1, 40],
  node_ids: [4, 5, 4, 7],
  parser: :prism},
 "block in <main>",
 "bug.rb",
 "/tmp/tmp.Fbq5WA0GnO/bug.rb",
 1,
 :block,
 [],
 {},
 [],
 [1,
  :RUBY_EVENT_LINE,
  :RUBY_EVENT_B_CALL,
  [:putself],
  [:putchilledstring, "Hello, World!"],
  [:opt_send_without_block, {mid: :puts, flag: 20, orig_argc: 1}],
  :RUBY_EVENT_B_RETURN,
  [:leave]]]
{arg_size: 0,
 local_size: 0,
 stack_max: 2,
 node_id: 7,
 code_location: [1, 13, 1, 40],
 node_ids: [4, 5, 4, 7],
 parser: :prism}
13

For context:

This second value being 13 instead of 15 is causing Rails tests to fail:
https://buildkite.com/rails/rails-nightly/builds/3447#019b710f-e78a-405f-8297-20d2e26b0912/L3277

We want:

 { @object.num }

But we get:

-> { @object.num }

I am pretty sure using the same version of prism:

/tmp/tmp.Fbq5WA0GnO => rbenv shell 4.1.0
/tmp/tmp.Fbq5WA0GnO => gem list | grep prism
prism (1.7.0)
/tmp/tmp.Fbq5WA0GnO => rbenv shell 4.0.0
/tmp/tmp.Fbq5WA0GnO => gem list | grep prism
prism (1.7.0)

We use this data to get the original source string of a block we use to decorate the assert_difference assertion:
https://github.com/rails/rails/blob/3d31d593e6cf0f82fa9bd0338b635af2f30d627b/activesupport/lib/active_support/testing/assertions.rb#L331-L363

https://api.rubyonrails.org/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_difference

Updated by nobu (Nobuyoshi Nakada) about 4 hours ago ยท Edited Actions #1 [ruby-core:124409]

  • Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONTNEED, 4.0: UNKNOWN

Probably it's because of c970d2941d56a862bb9bb3b808cb588c2982f436.
That is the indent is not related, but the behavior change.

Updated by nobu (Nobuyoshi Nakada) about 4 hours ago Actions #2

  • Subject changed from iseq code_location miss calculated indent to iseq code_location of proc changed
Actions

Also available in: PDF Atom