-
Notifications
You must be signed in to change notification settings - Fork 290
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
Address warning: literal string will be frozen in the future
warnings
#462
base: master
Are you sure you want to change the base?
Address warning: literal string will be frozen in the future
warnings
#462
Conversation
I think we should reasonably push back on these new warnings and the restriction itself. I don't think they realized how big of an impact it will be while negatively impacting performance at least in the short term. I have added a note: https://bugs.ruby-lang.org/issues/20205#note-55 |
I also found warnings by stdlib with @yahonda:
@mame found
from https://github.com/nahi/httpclient/blob/master/lib/httpclient/http.rb#L241 It's hard to fix that from |
The warning isn't really from The fix is to do: |
lib/httpclient.rb
Outdated
@@ -1240,7 +1240,7 @@ def do_get_block(req, proxy, conn, &block) | |||
conn.push(res) | |||
return res | |||
end | |||
content = block ? nil : '' | |||
content = block ? nil : String.new('') |
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.
content = block ? nil : String.new('') | |
content = block ? nil : ''.dup |
Why not a simple .dup
?
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.
Since these strings starts out as an empty string and the string is added later with the <<
method, I was feeling like it seemed more appropriate to create empty string via String.new than duplicating an empty string. However, I do not have strong opinion on this so let me update them to use dup.
An easy way to solve these warnings is to run ruby with |
This commit addresses the `warning: literal string will be frozen in the future` warnings appeared at Rails CI https://buildkite.com/rails/rails-nightly/builds/1122#019263a3-2200-4e62-a6a8-028cffa60aaf Here are the warnings appeared: ``` /usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient.rb:1256: warning: literal string will be frozen in the future /usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient/http.rb:580: warning: literal string will be frozen in the future /usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient/session.rb:954: warning: literal string will be frozen in the future /usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient/util.rb:71: warning: literal string will be frozen in the future ``` There should be some warnings remained because Rails CI does not use all of httpclient code. I'll open some pull requests later to address remaining ones. Ref: https://bugs.ruby-lang.org/issues/20205
a049d6f
to
409fa27
Compare
This commit addresses the
warning: literal string will be frozen in the future
warnings appeared at Rails CI https://buildkite.com/rails/rails-nightly/builds/1122#019263a3-2200-4e62-a6a8-028cffa60aafHere are the warnings appeared:
There should be some warnings remained because Rails CI does not use all of httpclient code. I'll open some pull requests later to address remaining ones.
Ref: https://bugs.ruby-lang.org/issues/20205