Last active
August 1, 2019 17:45
-
-
Save jrunning/fe882c32580e33c6aac436ec97453ee4 to your computer and use it in GitHub Desktop.
Sorbet weird $global type behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'sorbet', :group => :development | |
gem 'sorbet-runtime' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# typed: true | |
require "sorbet-runtime" | |
class Rollout; end | |
$rollout = T.let(Rollout.new, Rollout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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