ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:121389] [Ruby Bug#21187] Strings concatenated with `\` getting frozen with literal hashes (PRISM only)
@ 2025-03-17 21:10 LocoDelAssembly via ruby-core
  2025-04-14  7:46 ` [ruby-core:121655] " alanwu (Alan Wu) via ruby-core
  0 siblings, 1 reply; 2+ messages in thread
From: LocoDelAssembly via ruby-core @ 2025-03-17 21:10 UTC (permalink / raw)
  To: ruby-core; +Cc: LocoDelAssembly

Issue #21187 has been reported by LocoDelAssembly (Hernán Pereira).

----------------------------------------
Bug #21187: Strings concatenated with `\` getting frozen with literal hashes (PRISM only)
https://bugs.ruby-lang.org/issues/21187

* Author: LocoDelAssembly (Hernán Pereira)
* Status: Open
* ruby -v: ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
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.




-- 
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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:121655] [Ruby Bug#21187] Strings concatenated with `\` getting frozen with literal hashes (PRISM only)
  2025-03-17 21:10 [ruby-core:121389] [Ruby Bug#21187] Strings concatenated with `\` getting frozen with literal hashes (PRISM only) LocoDelAssembly via ruby-core
@ 2025-04-14  7:46 ` alanwu (Alan Wu) via ruby-core
  0 siblings, 0 replies; 2+ messages in thread
From: alanwu (Alan Wu) via ruby-core @ 2025-04-14  7:46 UTC (permalink / raw)
  To: ruby-core; +Cc: alanwu (Alan Wu)

Issue #21187 has been updated by alanwu (Alan Wu).

Assignee set to prism

----------------------------------------
Bug #21187: Strings concatenated with `\` getting frozen with literal hashes (PRISM only)
https://bugs.ruby-lang.org/issues/21187#change-112709

* Author: LocoDelAssembly (Hernán Pereira)
* Status: Open
* Assignee: prism
* ruby -v: ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
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.




-- 
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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-14  7:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-17 21:10 [ruby-core:121389] [Ruby Bug#21187] Strings concatenated with `\` getting frozen with literal hashes (PRISM only) LocoDelAssembly via ruby-core
2025-04-14  7:46 ` [ruby-core:121655] " alanwu (Alan Wu) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).