rails: frozen_string_literal cause errors when zeitwerk enabled

Steps to reproduce

  • Get the up-to-date rails:master code.
  • Run some pieces of code, starting with a # frozen_string_literal: true line.
  • App will throw FrozenError (can't modify frozen #<Class:#<Array:0x0000560cb028f588>>): in different parts of the application.

Actual behavior

After enabling zeitwerk, the files starting with # frozen_string_literal: true started to cause errors. More specifically I am getting lots of FrozenError (can't modify frozen #<Class:#<Array:0x0000560cb028f588>>): errors.

When I disable zeitwerk by adding config.autoloader = :classic to the application.rb, I’m not getting any errors.

When I don’t disable zeitwerk, but remove # frozen_string_literal: true line, I’m not getting any errors too.

System configuration

Rails version: 6.0.0.beta1:master

Ruby version: 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 25 (19 by maintainers)

Commits related to this issue

Most upvoted comments

OK, I think we have it. bootsnap has been updated and it is going to have a new release soon. Then, for extra peace of mind, merged the unhook in #35332 to remove AS::Dependencies’ const_missing altogether. With it we’ll bypass monkey patches to the private methods it invokes that may exist out there, as it was the case in the origin of these frozen errors.

Thanks a lot you guys for testing master, without these tests this gotcha would have shipped with beta2. And thanks a lot for the debugging session here with all the tests and shared traces, it was really instrumental to identify what was happening. ❤️

Well, fun times:

Add config.autoloader = :classic to application.rb, restart server => error goes away

but then

Remove config.autoloader = :classic from application.rb, restart server => error stays away

So there’s some interaction beyond whether it’s in classic mode.