[ruby-core:99560] [Ruby master Feature#17104] Do not freeze interpolated strings when using frozen-string-literal
From:
bughitgithub@...
Date:
2020-08-11 15:57:20 UTC
List:
ruby-core #99560
Issue #17104 has been updated by bughit (bug hit).
> another reason is avoidance of alias effects
What you've shown is not another reason for freezing.
`a = b = "My string"`
both a and b refer to the same string object regardless of interning/freezing
there's no expectation that mutating it via `a` will not affect `b`
the interning scenario is:
```rb
a = "My string"
b = "My string"
a.gsub!(/My/, 'Your')
```
here there's an appearance of 2 string objects but when they are interned, there's only one, so mutation can not be allowed. As I said, interning is the feature, and it requires freezing.
----------------------------------------
Feature #17104: Do not freeze interpolated strings when using frozen-string-literal
https://bugs.ruby-lang.org/issues/17104#change-87020
* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
----------------------------------------
```rb
#frozen_string_literal: true
def foo(str)
"#{str}"
end
fr1 = 'a'
fr2 = 'a'
fr1_1 = foo(fr1)
fr2_1 = foo(fr2)
puts fr1.__id__, fr2.__id__, fr1_1.__id__, fr2_1.__id__
puts fr1_1 << 'b'
```
Isn't the point of frozen literals to avoid needless allocations? But interpolated strings are allocated each time, so freezing appears pointless.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>