From: "Earlopain (Earlopain _) via ruby-core" <ruby-core@...>
Date: 2025-04-16T12:21:04+00:00
Subject: [ruby-core:121672] [Ruby Feature#21269] Opt in to raise for modification of chilled strings returned from `Symbol#to_s`

Issue #21269 has been reported by Earlopain (Earlopain _).

----------------------------------------
Feature #21269: Opt in to raise for modification of chilled strings returned from `Symbol#to_s`
https://bugs.ruby-lang.org/issues/21269

* Author: Earlopain (Earlopain _)
* Status: Open
----------------------------------------
Ref https://bugs.ruby-lang.org/issues/20350

```rb
begin
  :foo.to_s << "bar"
  puts "ok sym"
rescue
  puts "fail sym"
end

begin
  "foo" << "bar"
  puts "ok str"
rescue
  puts "failed str"
end
```

Output with `RUBYOPT="--enable=frozen-string-literal -W"`:
```
test.rb:2: warning: string returned by :foo.to_s will be frozen in the future
ok sym
failed str
```

`--enable=frozen-string-literal` does something for string literals, I would like the same for `Symbol#to_s`. I would suggest simply reusing `--enable=frozen-string-literal` but its name seems very clear about being about string literals, which doesn't really fit for what's going on with symbols here.

For convenience, it would be very nice to have just a single switch for this though.



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