Actions
Bug #21187
closedStrings concatenated with `\` getting frozen with literal hashes (PRISM only)
Bug #21187: Strings concatenated with `\` getting frozen with literal hashes (PRISM only)
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.
Actions