Skip to content
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

Force mutable Strings to address upcoming Ruby default frozen strings #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jqr
Copy link

@jqr jqr commented Dec 27, 2024

Ruby is slowly moving towards using frozen string literals by default. As of Ruby 3.4 it now produces a warning whenever a String literal modifies a value which will be default frozen in the future.

From this project:

lib/graphviz.rb:533: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
lib/graphviz/dot_script.rb:58: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)

This change minimally modifies the places where a mutable String is required to use String.new instead of a bare String literal. This is a no-op for existing apps not using default frozen strings, but allows all the benefits for applications supporting it.

Running the tests with the upcoming behavior enabled on Ruby 3.4:

RUBYOPT="--enable=frozen_string_literal" rake

Before:

100 tests, 303 assertions, 71 failures, 5 errors, 0 pendings, 0 omissions, 0 notifications
24% passed

After:

100 tests, 258 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Ruby is slowly moving towards using frozen string literals by default [1]. As
of Ruby 3.4 it now produces a warning whenever a String literal modifies a
value which will be default frozen in the future.

From this project:

```
lib/graphviz.rb:533: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
lib/graphviz/dot_script.rb:58: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
```

This change minimally modifies the places where a mutable String is required
to use String.new instead of a bare String literal. This is a no-op for
existing apps not using default frozen strings, but allows all the benefits
for applications supporting it.

Running the tests with the upcoming behavior enabled on Ruby 3.4:

```
RUBYOPT="--enable=frozen_string_literal" rake
```

Before:

```
100 tests, 303 assertions, 71 failures, 5 errors, 0 pendings, 0 omissions, 0 notifications
24% passed
```

After:

```
100 tests, 258 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
```

[1] https://bugs.ruby-lang.org/issues/20205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant