@@ -25,62 +25,6 @@ def not_nil!
2525 end
2626end
2727
28- # FIXME: this is load-order dependent, and will break if it's loaded after the real
29- # `T::Private::Types::Void::VOID` module, which is frozen:
30- # https://github.com/sorbet/sorbet/blob/f0cb505/gems/sorbet-runtime/lib/types/private/types/void.rb#L17-L19
31- if Bundler . locked_gems . specs . any? { |s | s . name == "sorbet-runtime" }
32- module TypeToolkit
33- module SorbetRuntimeCompatibility
34- module VoidPatch
35- # An override of `not_nil!` intended to reduce the discrepancy between test and production environments
36- # when Sorbet Runtime is used in tests but not production.
37- #
38- # When Sorbet Runtime is active `void`-returning methods have their return value replaced with the
39- # `T::Private::Types::Void::VOID` module. If Sorbet Runtime is on in tests but not production,
40- # this introduces a dangerous difference in behaviour for methods that return `nil`:
41- #
42- # * In test code, it'll be replaced with `T::Private::Types::Void::VOID`.
43- # If `not_nil!` is called on it (and this override didn't exist), it'll just return `self`.
44- #
45- # * In production code, that `nil` value will left-as-is, and calling `not_nil!` on it will raise an error.
46- #: -> bot
47- def not_nil!
48- # Do not rely on this message content! Its content is subject to change.
49- raise TypeToolkit ::UnexpectedNilError , "Called `not_nil!` on a void value (T::Private::Types::Void::VOID)"
50- end
51- end
52- end
53- end
54-
55- module T
56- module Types
57- class Base ; end
58- end
59-
60- module Private
61- module Types
62- class Void < T ::Types ::Base
63- if defined? ( ::T ::Private ::Types ::Void ::VOID )
64- # sorbet-runtime was already loaded, and the `VOID` module is already frozen, so we can't change it.
65- # Instead, replace it with our own copy.
66- ::T ::Private ::Types ::Void . const_set ( :VOID , ::Module . new do
67- extend ::TypeToolkit ::SorbetRuntimeCompatibility ::VoidPatch
68-
69- freeze # Freeze it like the original
70- end )
71- else
72- # sorbet-runtime hasn't been loaded yet, so we're defining the `VOID` module for the first time.
73- module VOID
74- extend ::TypeToolkit ::SorbetRuntimeCompatibility ::VoidPatch
75- # Leave it unfrozen so sorbet-runtime can freeze it later when it defines it.
76- end
77- end
78- end
79- end
80- end
81- end
82- end
83-
8428module TypeToolkit
8529 # An error raised when calling `#not_nil!` on a `nil` value.
8630 #
0 commit comments