Actions
Bug #21933
openRuby::Box: named capture local variable can become nil after non-matching lines
Bug #21933:
Ruby::Box: named capture local variable can become nil after non-matching lines
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
4.0.1
Description
Environment:
- Ruby 4.0.1
- RUBY_BOX=1
- OS: Linux x86_64
Summary:
With Ruby::Box enabled, a named capture local variable from =~ may become nil,
even when the regexp matches. This happens after iterating over non-matching lines first.
Reproducer:
sample.rb
text = <<~ASM
.intel_syntax noprefix
.globl main
main:
nop
ASM
cur=nil
text.each_line do |line|
if /^(?<label>[_A-Za-z.]\w*):/ =~ line
p [:matched, line.inspect, label.inspect]
cur = label
break
end
end
p [:cur, cur.inspect]
Expected:
[:matched, "\"main:\\n\"", "\"main\""]
[:cur, "\"main\""]
Actual (with RUBY_BOX=1):
[:matched, "\"main:\\n\"", "nil"]
[:cur, "nil"]
Control:
Without RUBY_BOX=1, the same script returns "main" as expected.
Actions