sorbet-runtime 0.5.5851 → 0.5.5863

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: c454cb15e39b7993b14f0351e090110a0f49b19f2fb851179699e1e70f87f9d2
4
- data.tar.gz: 37f92c032bd9af70232c7400549287cf9a026fb4137eeb7b1af23d95289e3286
3
+ metadata.gz: f848903aee26071b35bc3c642774c8856e5347a486acd4f1beeeea4a27e67472
4
+ data.tar.gz: 51ed3e44c8cdf3ddbc1691e40fbdd7070acd8d2a17bee15e6a811c234d7188ef
5
5
  SHA512:
6
- metadata.gz: 52989449f24b265c5612ed9916b107d0b81fb1565d6e70399f9f5d5b4bcf92c03b6cd6ecdbe9986cf8a4cead03b75a886ac133dcb076011e164cca15ebc464a9
7
- data.tar.gz: a4dc951f7c3572c7557870b57fdf5ef409c61858f909f4603b6c92999c2040ea29841a120b916d5a678c11c6d83468a357d5fe3ce15f60b9b9cdc5f3118f5732
6
+ metadata.gz: b9c6a1dfd845ac6566f75621d757db6631442652477ec4b3548334282af3d1864711625bff2072940fca648424567efa53be85268950d5964eaaa220da26d2b6
7
+ data.tar.gz: c09ccc4ddb6c2ff95cd8b4f673171c93f379f19c5c878b71072357e02749eb368eeb5614ffb03ecb05a5afe32b6b64663f6fce804ceb242fa8bc0670b8f6dafc
@@ -207,7 +207,11 @@ module T::Private::Methods
207
207
  new_method = nil
208
208
  T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
209
209
  method_sig = T::Private::Methods.maybe_run_sig_block_for_method(new_method)
210
- method_sig ||= T::Private::Methods._handle_missing_method_signature(mod, original_method, __callee__)
210
+ method_sig ||= T::Private::Methods._handle_missing_method_signature(
211
+ self,
212
+ original_method,
213
+ __callee__,
214
+ )
211
215
 
212
216
  # Should be the same logic as CallValidation.wrap_method_if_needed but we
213
217
  # don't want that extra layer of indirection in the callstack
@@ -238,28 +242,40 @@ module T::Private::Methods
238
242
  end
239
243
  end
240
244
 
241
- def self._handle_missing_method_signature(mod, original_method, callee)
245
+ def self._handle_missing_method_signature(receiver, original_method, callee)
242
246
  method_sig = T::Private::Methods.signature_for_method(original_method)
243
- aliasing_method = mod.instance_method(callee)
244
-
245
- if method_sig && aliasing_method != original_method && aliasing_method.original_name == original_method.name
246
- # We're handling a case where `alias` or `alias_method` was called for a
247
- # method which had already had a `sig` applied.
248
- #
249
- # Note, this logic is duplicated above, make sure to keep changes in sync.
250
- if method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
251
- # Checked, so copy the original signature to the aliased copy.
252
- T::Private::Methods.unwrap_method(mod, method_sig, aliasing_method)
253
- else
254
- # Unchecked, so just make `alias_method` behave as if it had been called pre-sig.
255
- mod.send(:alias_method, callee, original_method.name)
256
- end
257
- else
258
- raise "`sig` not present for method `#{aliasing_method.name}` but you're trying to run it anyways. " \
247
+ if !method_sig
248
+ raise "`sig` not present for method `#{callee}` on #{receiver.inspect} but you're trying to run it anyways. " \
259
249
  "This should only be executed if you used `alias_method` to grab a handle to a method after `sig`ing it, but that clearly isn't what you are doing. " \
260
250
  "Maybe look to see if an exception was thrown in your `sig` lambda or somehow else your `sig` wasn't actually applied to the method."
261
251
  end
262
252
 
253
+ if receiver.class <= original_method.owner
254
+ receiving_class = receiver.class
255
+ elsif receiver.singleton_class <= original_method.owner
256
+ receiving_class = receiver.singleton_class
257
+ elsif receiver.is_a?(Module) && receiver <= original_method.owner
258
+ receiving_class = receiver
259
+ else
260
+ raise "#{receiver} is not related to #{original_method} - how did we get here?"
261
+ end
262
+
263
+ # Check for a case where `alias` or `alias_method` was called for a
264
+ # method which had already had a `sig` applied. In that case, we want
265
+ # to avoid hitting this slow path again, by moving to a faster validator
266
+ # just like we did or will for the original method.
267
+ #
268
+ # If this isn't an `alias` or `alias_method` case, we're probably in the
269
+ # middle of some metaprogramming using a Method object, e.g. a pattern like
270
+ # `arr.map(&method(:foo))`. There's nothing really we can do to optimize
271
+ # that here.
272
+ receiving_method = receiving_class.instance_method(callee)
273
+ if receiving_method != original_method && receiving_method.original_name == original_method.name
274
+ aliasing_mod = receiving_method.owner
275
+ method_sig = method_sig.as_alias(callee)
276
+ unwrap_method(aliasing_mod, method_sig, original_method)
277
+ end
278
+
263
279
  method_sig
264
280
  end
265
281
 
@@ -281,7 +297,7 @@ module T::Private::Methods
281
297
  Signature.new_untyped(method: original_method)
282
298
  end
283
299
 
284
- unwrap_method(hook_mod, signature, original_method)
300
+ unwrap_method(signature.method.owner, signature, original_method)
285
301
  signature
286
302
  end
287
303
 
@@ -333,8 +349,8 @@ module T::Private::Methods
333
349
  end
334
350
  end
335
351
 
336
- def self.unwrap_method(hook_mod, signature, original_method)
337
- maybe_wrapped_method = CallValidation.wrap_method_if_needed(signature.method.owner, signature, original_method)
352
+ def self.unwrap_method(mod, signature, original_method)
353
+ maybe_wrapped_method = CallValidation.wrap_method_if_needed(mod, signature, original_method)
338
354
  @signatures_by_method[method_to_key(maybe_wrapped_method)] = signature
339
355
  end
340
356
 
@@ -121,6 +121,15 @@ class T::Private::Methods::Signature
121
121
  end
122
122
  end
123
123
 
124
+ attr_writer :method_name
125
+ protected :method_name=
126
+
127
+ def as_alias(alias_name)
128
+ new_sig = clone
129
+ new_sig.method_name = alias_name
130
+ new_sig
131
+ end
132
+
124
133
  def arg_count
125
134
  @arg_types.length
126
135
  end
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.5851
4
+ version: 0.5.5863
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest