From: "Earlopain (Earlopain _) via ruby-core" Date: 2026-01-14T14:47:49+00:00 Subject: [ruby-core:124538] [Ruby Bug#21816] iseq code_location of proc changed Issue #21816 has been updated by Earlopain (Earlopain _). The change in `RubyVM::AST.of` seems to have been introduced in http://github.com/ruby/ruby/commit/2ccb2de677849732181224cb9fd1a831dbaac4c0. There is a test update where the source for the proc `Proc.new { 1 + 2 }` changes from `{ 1 + 2 }` to `Proc.new { 1 + 2 }` so that seems intentional. The same is also true for stabby lambdas. So I guess you could say that the change in 4.1 more closely matches the behaviour you get from `RubyVM::AST`. On the other hand, `RubyVM::IS.of` doesn't include the block receiver. That was briefly brought up in https://bugs.ruby-lang.org/issues/21784 but I don't think it got mentioned again. ---------------------------------------- Bug #21816: iseq code_location of proc changed https://bugs.ruby-lang.org/issues/21816#change-116106 * Author: zzak (zzak _) * Status: Open * Backport: 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONTNEED, 4.0: UNKNOWN ---------------------------------------- TBH, I'm not really sure if that title matches the problem here, but I can produce this issue with the following test: ```ruby # 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
", "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
", "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 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/