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

Make the spec suite compatible with --enable-frozen-string-literal #1142

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

casperisfine
Copy link
Contributor

Extracted from: ruby/ruby#10235

Ref: https://bugs.ruby-lang.org/issues/20205

Ruby will gradually move towards enabling frozen string literals by default. Making the ruby spec suite compatible is a good first step.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@casperisfine casperisfine force-pushed the frozen-string-literal-compat branch 3 times, most recently from 9fc10ea to c237217 Compare March 13, 2024 19:08
@casperisfine
Copy link
Contributor Author

Alright I think it's going green now.

For some specs like most of everything in core/string I just went with a # frozen_string_literal: false as many of these tests involved string mutation anyway, but for other parts I tried not to rely on it too much as to not "calcify" the spec suite, and properly test compatibility with --enable-frozen-string-literals.

The overwhelming majority of the diff is just some extra + or .dup.

@casperisfine casperisfine force-pushed the frozen-string-literal-compat branch 5 times, most recently from cad7b94 to 10edfdf Compare March 13, 2024 19:22
@casperisfine casperisfine marked this pull request as ready for review March 13, 2024 22:35
Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, I'll push some minor changes when I'm done reviewing, I'm still in the process of reviewing the 250 files changed.

core/array/pack/buffer_spec.rb Outdated Show resolved Hide resolved
core/array/shared/inspect.rb Show resolved Hide resolved
core/array/shared/inspect.rb Outdated Show resolved Hide resolved
Comment on lines 19 to 25
real = NumericSpecs::Subclass.new
real.should_receive(:inspect).and_return("1")
real.should_receive(:inspect).and_return(+"1")
imaginary = NumericSpecs::Subclass.new
imaginary.should_receive(:inspect).and_return("2")
imaginary.should_receive(:inspect).and_return(+"2")
imaginary.should_receive(:<).any_number_of_times.and_return(false)
Complex(real, imaginary).inspect.should == "(1+2i)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird, Complex#inspect mutates the string returned from real.inspect, that seems really wrong.
Probably something to fix in CRuby: https://bugs.ruby-lang.org/issues/20337

Extracted from: ruby/ruby#10235

Ref: https://bugs.ruby-lang.org/issues/20205

Ruby will gradually move towards enabling frozen string literals
by default. Making the ruby spec suite compatible is a good first
step.

Co-authored-by: Benoit Daloze <eregontp@gmail.com>
@eregon eregon force-pushed the frozen-string-literal-compat branch from 668a76e to 0be2f8b Compare March 14, 2024 16:40
@eregon
Copy link
Member

eregon commented Mar 14, 2024

I made a separate PR to get a better diff for review: #1143
@andrykonchin Could you take a look to get another pair of eyes on it?

I'll merge this PR because I went through like 99% of the diff so I think it's all correct, just maybe some extra + left.
Maybe we should also remove more # frozen_string_literal: false to have a more consistent default in ruby/spec, although I already removed basically all except in String specs for mutable methods + a few extra specs which make more sense with false.

@eregon eregon merged commit 028bc68 into ruby:master Mar 14, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants