Issue #20389 has been updated by byroot (Jean Boussier).
Assignee set to byroot (Jean Boussier)
Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0:
DONTNEED, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED
----------------------------------------
Bug #20389: Issue with chilled strings and mutability after 12be40ae
https://bugs.ruby-lang.org/issues/20389#change-107445
* Author: mdalessio (Mike Dalessio)
* Status: Open
* Assignee: byroot (Jean Boussier)
* ruby -v: ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
* Backport: 3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED
----------------------------------------
Commit 12be40ae introduced the concept of "chilled" strings when code is
compiled with frozen-string-literals not explicitly enabled or disabled. I believe
I've found a related bug, which I've bisected to this commit.
This reproduction has been simplified from a failing test case in the `http-cookie` gem:
``` ruby
puts RUBY_DESCRIPTION
re = %r{.(?<thing>.*)}
input = "x/dir[]/file.html"
match = re.match(input) # => "#<MatchData \"x/dir[]/file.html\"
thing:\"/dir[]/file.html\">"
thing = match[:thing]
puts "before: #{thing.inspect}"
input[match.begin(:thing)...match.end(:thing)] = "/dir%5B%5D/file.html"
puts "after : #{thing.inspect}"
exit 1 unless thing == "/dir[]/file.html"
```
Ruby 3.3.0 and earlier is fine:
```
$ ruby ./issue-chilled-strings.rb
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
before: "/dir[]/file.html"
after : "/dir[]/file.html"
```
Master with frozen string explicitly disabled passes:
```
$ ruby --disable-frozen-string-literal ./issue-chilled-strings.rb
ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
before: "/dir[]/file.html"
after : "/dir[]/file.html"
```
Master with frozen strings explicitly enabled fails as expected:
```
$ ruby --enable-frozen-string-literal ./issue-chilled-strings.rb
ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
before: "/dir[]/file.html"
./issue-chilled-strings.rb:12:in 'String#[]=': can't modify frozen String:
"x/dir[]/file.html" (FrozenError)
from ./issue-chilled-strings.rb:12:in '<main>'
```
But master with no frozen string setting ("chilled") fails, and modifies what
should be a frozen string:
```
$ ruby ./issue-chilled-strings.rb
ruby 3.4.0dev (2024-03-23T16:40:17Z master 8265a7531f) [x86_64-linux]
before: "/dir[]/file.html"
after : "/dir%5B%5D/file."
```
I believe in this case, the chilled warning should be emitted, but then the frozen string
should not be modified.
--
https://bugs.ruby-lang.org/