-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply frozen string literal magic comment #424
Apply frozen string literal magic comment #424
Conversation
f67b8d5
to
4cdb305
Compare
Starting with Ruby 3.4, there is a gradual plan to freeze strings: https://bugs.ruby-lang.org/issues/20205#note-35 Using Ruby 3.4dev with code prior to this PR results in the following warning: ```console $ cd path/to/ruby/lrama $ ruby -v ruby 3.4.0dev (2024-05-27T01:45:38Z master 5853a38043) [x86_64-darwin23] $ RUBYOPT=-W:deprecated bundle exec rake (snip) /Users/koic/src/github.com/ruby/lrama/lib/lrama/output.rb:74: warning: literal string will be frozen in the future ``` This warning suggests that applying the frozen string magic comment will lead to `FrozenError`. So, this indicates that the future behavior of (default frozen) string will produce `FrozenError`. This PR applies the frozen string magic comment to detect `FrozenError` and uses `String#dup` to prevent it: https://gist.github.com/fxn/bf4eed2505c76f4fca03ab48c43adc72#ruby-34 This ensures compatibility for the future. NOTE: From Ruby 3.3+, there is no speed difference between `String#+@` and `String#dup`. For readability, `String#dup` has been chosen: ruby/ruby#8952
4cdb305
to
c335174
Compare
Thank you for your contribution. I believe I understand the issue you have pointed out correctly, and it is necessary to address this to support CRuby 3.4 and later. However, I do not think the diff you proposed is the best solution to apply across the entire project for two main reasons:
|
Thank you for considering this. Here are my thoughts on each point:
How to proceed with this PR is up to the maintainers' discretion. Thank you. |
Thank you for making this suggestion. Perhaps @junk0612 concerned about reining in with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @ydah . I was reluctant to propose my opinion because of some concerns, but now that you have created a follow up, we can discuss it there, I think this PR is good to merge.
Starting with Ruby 3.4, there is a gradual plan to freeze strings: https://bugs.ruby-lang.org/issues/20205#note-35
Using Ruby 3.4dev with code prior to this PR results in the following warning:
This warning suggests that applying the frozen string magic comment will lead to
FrozenError
. So, this indicates that the future behavior of (default frozen) string will produceFrozenError
.This PR applies the frozen string magic comment to detect
FrozenError
and usesString#dup
to prevent it: https://gist.github.com/fxn/bf4eed2505c76f4fca03ab48c43adc72#ruby-34This ensures compatibility for the future.
NOTE: From Ruby 3.3+, there is no speed difference between
String#+@
andString#dup
. For readability,String#dup
has been chosen: ruby/ruby#8952