sorbet-runtime 0.5.6432 → 0.5.6442

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0ee12af2b28dcd17f0c18edf81bbe9628cecfb58ec5ac2c8342151a8ac1bf99
4
- data.tar.gz: f3cce70dbbb1c940987f3c2e0a1f09231f0e05306a9fc1cd97ea6c55a79ce131
3
+ metadata.gz: 8805689d39483edeab9d97a1235f0eba1fad5e20ffed87ef4c24679e7c832525
4
+ data.tar.gz: 60c23ac8a2301badb0bfbd0c2d0bb8ddc3c7814616947cad6524d00ec37db1a4
5
5
  SHA512:
6
- metadata.gz: 6b633d3207446dc37a918eaf63f3925b385ed9e1b53e4460af3d35be7a319fefe3be6677373b45134efb9429fb07bc9cc90c091b603eb452f7fa10c87997e77d
7
- data.tar.gz: 0e92d8d4adca81d147fcab425ab9a82ca1b3296c477e7afaa9991e6daa4ad743aeccf965cb79bb3b0705b44119ea03a16024eb766e9d565ce2286fc58496752f
6
+ metadata.gz: 0a9941b93820e638d900c6f321736a08cd061538c9f3885fb39d8e63ab787373b38d825c3933baa633143e9b4ad9dba747d17d67967e873995a88c091bcb01e3
7
+ data.tar.gz: 86d69bc3ed1ac34a06a73b170a94e521829faf025d98562f92ce46891eb148cdc78be4aae94c75f364b36cc32a6d5669a5ca0ec6976c187c84150302e9c8fe1d
@@ -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.6432
4
+ version: 0.5.6442
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-03 00:00:00.000000000 Z
11
+ date: 2021-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest