Actions
Bug #21187
openStrings concatenated with `\` getting frozen with literal hashes (PRISM only)
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-linux]
Description
When the first elements of a literal hash are strings that are concatenated with \
, those elements are flagged with PM_NODE_FLAG_STATIC_LITERAL
and a special optimization that I believe was introduced in https://github.com/ruby/ruby/commit/8080de04be8e99e71309745822a9d436cc4ae37c causes the strings to be frozen.
Reproduction¶
test.rb
a = {
a: 'one' \
'two',
b: 'three' \
'four',
c: 'five',
d: 'six' \
'seven'
}
b = {
a: 'one',
b: 'two' \
'three'
}
puts "a = #{a.map { |k,v| {k => v.frozen?} }}"
puts "b = #{b.map { |k,v| {k => v.frozen?} }}"
With prism:
$ ruby test.rb
a = [{a: true}, {b: true}, {c: false}, {d: false}]
b = [{a: false}, {b: false}]
With parse.y:
$ ruby --parser=parse.y test.rb
a = [{a: false}, {b: false}, {c: false}, {d: false}]
b = [{a: false}, {b: false}]
(Notice b
hash is unaffected in both parsers)
Not sure if this is just part of undefined behavior or this is indeed a bug. Assigning a string concatenated with \
to a variable doesn't make it frozen, to the best of my knowledge this seems to be hash-specific.
No data to display
Actions
Like0