Avoid frozen-string-literal warnings in Ruby 3.4#27
Open
kindjar wants to merge 3 commits intoopencoconut:masterfrom
Open
Avoid frozen-string-literal warnings in Ruby 3.4#27kindjar wants to merge 3 commits intoopencoconut:masterfrom
kindjar wants to merge 3 commits intoopencoconut:masterfrom
Conversation
Since the same files would be written—and cleaned up—by several other tests, these files might or might not be left behind, depending on the order in which tests were run.
In Ruby 3.4, by default string literals are “chilled” and if a chilled string is modified, a warning is emitted (https://bugs.ruby-lang.org/issues/20205). Replace string literals that are intended to be modified with a call to String.new, which produces a fresh mutable string each invocation.
This pragma is supported back to Ruby 2.3 and prohibits modifying string literals, which will (someday?) be frozen by default in Ruby.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Ruby 3.4, string literals are "chilled" by default, and if chilled strings are modified, a warning is emitted (see https://bugs.ruby-lang.org/issues/20205 for details). There are a couple of places in webvtt-ruby where a variable is initialized with an empty string literal and then appended, which triggers these warnings. The clearest fix for these is to replace the empty string literal with a call to
String.new.I'm hoping you are open to a pull request to address these warnings under Ruby 3.4?
I also discovered that one of the test cases wasn't cleaning up files the way other tests did, and addressed that.
And finally, I added the
frozen_string_literal: truepragma to the ruby source files, which will cause any future attempts to modify a frozen string literal to raise an error, so that no other warning sneak in.I'm happy to pare this down if you prefer not add the pragma.
Thanks for your consideration!