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

Add frozen string literal support #695

Merged
merged 1 commit into from
Apr 7, 2020
Merged

Add frozen string literal support #695

merged 1 commit into from
Apr 7, 2020

Conversation

deivid-rodriguez
Copy link
Contributor

I created this but when I was forking the gem, I noticed that it's already fixed on https://github.com/ruby/rdoc/tree/fix-for-frozen-string-literal. And the test there is probably better than re-running everything 🤷‍♂️.

@yuki24
Copy link
Member

yuki24 commented Feb 18, 2019

If it's already fixed, I think we could always run the entire test suite with RUBYOPT=--enable-frozen_string_literal specified.

What do you think? @hsbt @aycabta

@deivid-rodriguez
Copy link
Contributor Author

It's fixed but only on a branch that has not been incorporated to master. Maybe it has other problems? 🤷‍♂️. Something to be noted is that this patch does not pass CI with string literals enabled under ruby 2.3 for some reason.

@esparta
Copy link

esparta commented Jul 17, 2019

It's an interesting problem here. Checking the logs in Travis CI, the problem is not rdoc itself but ERB who, apparently is not frozen-string complaint in ruby 2.3:

Test file:

# frozen_string_literal: true

require 'erb'

x = 42

template = ERB.new <<-EOF
  The value of x is: <%= x %>
EOF
puts template.result(binding)

Ruby 2.3:

$ ruby --version
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]

$ ruby erb_testing.rb
  The value of x is: 42
$ RUBYOPT=--enable-frozen_string_literal ruby erb_testing.rb
(erb):1:in `concat': can't modify frozen String (RuntimeError)
        from (erb):1:in `<main>'
        from /usr/local/lib/ruby/2.3.0/erb.rb:864:in `eval'
        from /usr/local/lib/ruby/2.3.0/erb.rb:864:in `result'
        from erb_testing.rb:9:in `<main>'

Meanwhile in Ruby 2.4 and later:

$ ruby --version
ruby 2.4.6p354 (2019-04-01 revision 67394) [x86_64-linux]

$ ruby erb_testing.rb 
  The value of x is: 42
$ RUBYOPT=--enable-frozen_string_literal ruby erb_testing.rb
  The value of x is: 42

I was not able to test the same in the minimal version supported(ruby 2.2) because it has no way to enable frozen string:

$ ruby --version
ruby 2.2.10p489 (2018-03-28 revision 63023) [x86_64-linux]

$ ruby erb_testing.rb 
  The value of x is: 42
$ RUBYOPT=--enable-frozen_string_literal ruby erb_testing.rb
ruby: warning: unknown argument for --enable: `frozen_string_literal'
  The value of x is: 42

IMO, having RUBYOPT=--enable-frozen_string_literal in ruby 2.3 is not a real use case because it would break not only rdoc but (probably) most of the apps running in that version.

@deivid-rodriguez
Copy link
Contributor Author

Since 2.3 support has been dropped, I rebased this PR and it's now green.

@ioquatix ioquatix merged commit daac9d0 into ruby:master Apr 7, 2020
@ioquatix
Copy link
Member

ioquatix commented Apr 7, 2020

LGTM.

@deivid-rodriguez deivid-rodriguez deleted the frozen_string_literals branch April 7, 2020 13:14
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.

4 participants