sorbet-rails icon indicating copy to clipboard operation
sorbet-rails copied to clipboard

Cannot change default_checked_level of Sorbet when using this gem.

Open shoffing opened this issue 3 years ago • 3 comments

Describe the bug:

This gem makes it impossible to set T::Configuration.default_checked_level in a Rails app.

I suspect this is the same issue as found and fixed here: https://github.com/sorbet/sorbet/issues/2717 which was caused by type signatures being loaded during sorbet-runtime initialization. sorbet-rails must be doing the same thing somewhere during initialization.

Steps to reproduce:

Create a new Rails app, install sorbet-rails, set T::Configuration.default_checked_level = :tests in config/initializers/sorbet.rb, try and start the Rails app.

rails new sorbet_rails_bug
cd sorbet_rails_bug
rails webpacker:install
bundle add sorbet --group="development"
bundle add sorbet-runtime
bundle add sorbet-rails
bundle install
SRB_YES=1 bundle exec srb init
echo "T::Configuration.default_checked_level = :tests" >> config/initializers/sorbet.rb
rails s

This fails with:

/home/shoffing/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.6393/lib/types/private/runtime_levels.rb:48:in `default_checked_level=': Set the default checked level earlier. There are already some methods whose sig blocks have evaluated which would not be affected by the new default. (RuntimeError)

Note this does not fail when sorbet-rails is not installed.

Expected behavior:

This library would not interfere with the ability to change Sorbet's default checked level.

Versions:

  • Ruby: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
  • Rails: Rails 6.0.3.6
  • Sorbet: Sorbet typechecker 0.5.6393 git ae3bc7d005f3
  • Sorbet-Rails: latest

shoffing avatar Apr 28 '21 14:04 shoffing

I'm also experiencing this. I want to iteratively add type checking, but don't want to impact the current system with possible errors. Not being able to set this up really makes things a bit more risky.

kevinjcoleman avatar Jan 06 '22 14:01 kevinjcoleman

I'm also seeing this error on a Rails 7 app.

rodrei avatar Sep 02 '22 22:09 rodrei

A different but related scenario: I'm also experiencing this problem because of the shopify_app gem that is making sorbet raise an error. I'm trying to disable sorbet runtime check to workaround that gem's bug.

yogodoshi avatar Jan 15 '23 01:01 yogodoshi