Skip to content

Instantly share code, notes, and snippets.

@jrunning
Last active August 1, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrunning/fe882c32580e33c6aac436ec97453ee4 to your computer and use it in GitHub Desktop.
Save jrunning/fe882c32580e33c6aac436ec97453ee4 to your computer and use it in GitHub Desktop.
Sorbet weird $global type behavior
gem 'sorbet', :group => :development
gem 'sorbet-runtime'
# typed: true
require "sorbet-runtime"
require "./rollout_setup"
extend T::Sig
T.reveal_type($rollout) # => T.untyped (incorrect)
sig { params(val: Rollout).returns(Rollout) }
def expects_rollout(val)
val
end
expects_rollout($rollout) # no error (as expected)
expects_rollout("not a Rollout") # error (as expected)
$rollout = 123 # no error (not expected)
# typed: true
require "sorbet-runtime"
class Rollout; end
$rollout = T.let(Rollout.new, Rollout)
main.rb:7: Revealed type: `T.untyped` https://srb.help/7014
7 |T.reveal_type($rollout) # => T.untyped (incorrect)
^^^^^^^^^^^^^^^^^^^^^^^
From:
main.rb:15: Expected `Rollout` but found `String("not a Rollout")` for argument `val` https://srb.help/7002
15 |expects_rollout("not a Rollout") # error (as expected)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
main.rb:9: Method `Object#expects_rollout` has specified `val` as `Rollout`
9 |sig { params(val: Rollout).returns(Rollout) }
^^^
Got String("not a Rollout") originating from:
main.rb:15:
15 |expects_rollout("not a Rollout") # error (as expected)
^^^^^^^^^^^^^^^
Errors: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment