sorbet-runtime 0.5.6427 → 0.5.6440

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7132225afab6f9f847d25c97a4b525e3b3160691eb15cfc69c48bbb345725b3f
4
- data.tar.gz: 2937bf5f74dab485511ca6ca27cb149ff3fdd15bcc1f7c466ad35400424cbeeb
3
+ metadata.gz: 82d17038dfef0384936b69a24b7d37c97945f59f68e06d18957342fa64b8da9a
4
+ data.tar.gz: 123e19aa974da28f5c7cda255ed7ef792dae8bf4d5cb189fd809a652a27acb8b
5
5
  SHA512:
6
- metadata.gz: 5dcea3f7988da0ccf7d2068eb724415e13197b4a68a37b2f0aa9ce1627d72c6239d9a23c2f1314fff216302a656529a16074cf42f5b6c9d674e671af878907d0
7
- data.tar.gz: f79af251532558136042cae0dc0b967fe1178d4aa7544a15265aa97505b487ddc0b4759f065a5ed764bd9fc0964ced99151e2fa5cd96aeb68b7dbfdf6440cc80
6
+ metadata.gz: f873aeb24b8ec3bccb66a8909f77cd4e5dce30a41a189d63b7ead5fbe3757924e581bab19aec9effa0874d1d73fae91369a3c81127cbcd18c798753d9bbd5949
7
+ data.tar.gz: 42ffd5ad1aa8bf6fc52335a612eed179691e005bf9afeb7dd38c596bfcc2524ea2f21b1c09bdfce7c3d87d3f383a5a59642ad7eebf8997c1a5a6e57422f0ce29
@@ -26,6 +26,8 @@ module T::Private::Methods
26
26
  # in installed_hooks.
27
27
  @old_hooks = nil
28
28
 
29
+ @declaring_final_method = false
30
+
29
31
  ARG_NOT_PROVIDED = Object.new
30
32
  PROC_TYPE = Object.new
31
33
 
@@ -180,6 +182,17 @@ module T::Private::Methods
180
182
  @modules_with_final[mod.singleton_class]
181
183
  end
182
184
 
185
+ # See tests for how to use this.
186
+ def self._with_declaring_final_method_INTERNAL(&blk)
187
+ begin
188
+ prev_value = @declaring_final_method
189
+ @declaring_final_method = true
190
+ yield
191
+ ensure
192
+ @declaring_final_method = prev_value
193
+ end
194
+ end
195
+
183
196
  # Only public because it needs to get called below inside the replace_method blocks below.
184
197
  def self._on_method_added(hook_mod, method_name, is_singleton_method: false)
185
198
  if T::Private::DeclState.current.skip_on_method_added
@@ -189,7 +202,9 @@ module T::Private::Methods
189
202
  current_declaration = T::Private::DeclState.current.active_declaration
190
203
  mod = is_singleton_method ? hook_mod.singleton_class : hook_mod
191
204
 
192
- if T::Private::Final.final_module?(mod) && (current_declaration.nil? || !current_declaration.final)
205
+ directly_declaring_final_method = @declaring_final_method
206
+ method_is_final = directly_declaring_final_method || current_declaration&.final
207
+ if T::Private::Final.final_module?(mod) && !method_is_final
193
208
  raise "#{mod} was declared as final but its method `#{method_name}` was not declared as final"
194
209
  end
195
210
  # Don't compute mod.ancestors if we don't need to bother checking final-ness.
@@ -212,46 +227,49 @@ module T::Private::Methods
212
227
  )
213
228
  end
214
229
 
215
- original_method = mod.instance_method(method_name)
216
- sig_block = lambda do
217
- T::Private::Methods.run_sig(hook_mod, method_name, original_method, current_declaration)
218
- end
219
-
220
- # Always replace the original method with this wrapper,
221
- # which is called only on the *first* invocation.
222
- # This wrapper is very slow, so it will subsequently re-wrap with a much faster wrapper
223
- # (or unwrap back to the original method).
224
- key = method_owner_and_name_to_key(mod, method_name)
225
- T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
226
- method_sig = T::Private::Methods.maybe_run_sig_block_for_key(key)
227
- method_sig ||= T::Private::Methods._handle_missing_method_signature(
228
- self,
229
- original_method,
230
- __callee__,
231
- )
230
+ unless directly_declaring_final_method
231
+ original_method = mod.instance_method(method_name)
232
+ sig_block = lambda do
233
+ T::Private::Methods.run_sig(hook_mod, method_name, original_method, current_declaration)
234
+ end
232
235
 
233
- # Should be the same logic as CallValidation.wrap_method_if_needed but we
234
- # don't want that extra layer of indirection in the callstack
235
- if method_sig.mode == T::Private::Methods::Modes.abstract
236
- # We're in an interface method, keep going up the chain
237
- if defined?(super)
238
- super(*args, &blk)
236
+ # Always replace the original method with this wrapper,
237
+ # which is called only on the *first* invocation.
238
+ # This wrapper is very slow, so it will subsequently re-wrap with a much faster wrapper
239
+ # (or unwrap back to the original method).
240
+ key = method_owner_and_name_to_key(mod, method_name)
241
+ T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
242
+ method_sig = T::Private::Methods.maybe_run_sig_block_for_key(key)
243
+ method_sig ||= T::Private::Methods._handle_missing_method_signature(
244
+ self,
245
+ original_method,
246
+ __callee__,
247
+ )
248
+
249
+ # Should be the same logic as CallValidation.wrap_method_if_needed but we
250
+ # don't want that extra layer of indirection in the callstack
251
+ if method_sig.mode == T::Private::Methods::Modes.abstract
252
+ # We're in an interface method, keep going up the chain
253
+ if defined?(super)
254
+ super(*args, &blk)
255
+ else
256
+ raise NotImplementedError.new("The method `#{method_sig.method_name}` on #{mod} is declared as `abstract`. It does not have an implementation.")
257
+ end
258
+ # Note, this logic is duplicated (intentionally, for micro-perf) at `CallValidation.wrap_method_if_needed`,
259
+ # make sure to keep changes in sync.
260
+ elsif method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
261
+ CallValidation.validate_call(self, original_method, method_sig, args, blk)
262
+ elsif T::Configuration::AT_LEAST_RUBY_2_7
263
+ original_method.bind_call(self, *args, &blk)
239
264
  else
240
- raise NotImplementedError.new("The method `#{method_sig.method_name}` on #{mod} is declared as `abstract`. It does not have an implementation.")
265
+ original_method.bind(self).call(*args, &blk)
241
266
  end
242
- # Note, this logic is duplicated (intentionally, for micro-perf) at `CallValidation.wrap_method_if_needed`,
243
- # make sure to keep changes in sync.
244
- elsif method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
245
- CallValidation.validate_call(self, original_method, method_sig, args, blk)
246
- elsif T::Configuration::AT_LEAST_RUBY_2_7
247
- original_method.bind_call(self, *args, &blk)
248
- else
249
- original_method.bind(self).call(*args, &blk)
250
267
  end
268
+
269
+ @sig_wrappers[key] = sig_block
251
270
  end
252
271
 
253
- @sig_wrappers[key] = sig_block
254
- if current_declaration.final
272
+ if method_is_final
255
273
  @was_ever_final_names.add(method_name)
256
274
  # use hook_mod, not mod, because for example, we want class C to be marked as having final if we def C.foo as
257
275
  # final. change this to mod to see some final_method tests fail.
data/lib/types/utils.rb CHANGED
@@ -79,10 +79,12 @@ module T::Utils
79
79
  case type
80
80
  when T::Types::Union
81
81
  non_nil_types = type.types.reject {|t| t == Nilable::NIL_TYPE}
82
- if non_nil_types.length == 1
83
- non_nil_types.first
82
+ return nil if type.types.length == non_nil_types.length
83
+ case non_nil_types.length
84
+ when 0 then nil
85
+ when 1 then non_nil_types.first
84
86
  else
85
- nil
87
+ T::Types::Union::Private::Pool.union_of_types(non_nil_types[0], non_nil_types[1], non_nil_types[2..])
86
88
  end
87
89
  else
88
90
  nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6427
4
+ version: 0.5.6440
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-29 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest