sorbet-runtime 0.5.5858 → 0.5.5866

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: ddae56dee53b7a4ae6c91b0ff2a279c9238255402a97a12d5c1cff9efd6e5777
4
- data.tar.gz: 8de90de6b27854ae87ac9671d799e7d2fa2a2b4a4bde1a18d1574975b47f34a3
3
+ metadata.gz: 06f33bba34b08fbaf66e39ea5e8db2cee1d70f5f84340b85e6ed43582cebc745
4
+ data.tar.gz: dd8398d38b60baae1f7547d4bf8f1e39bf74e3c24bee18d72dd531011d44a35e
5
5
  SHA512:
6
- metadata.gz: 33be9484fb679eacae0992574ff30492e4549ae0a63a4c17d3348bf7e514bf6f62162f58290c6b9a674e38a27343be3a13f9b9bdcd20d99d804a47719bf4206c
7
- data.tar.gz: 560140944b988f084d31c7b04ff32d9f8a02f87e6a0a99d3956493f0cf7ae87fad51f032b0aced1ba6a48bf1eaa7c1b89bfc15a10330c752229dc541a2b4ae17
6
+ metadata.gz: eea13fe538193883ed4d03053106273d8dfabf654b9db38d18c5fae05960743ede7ea777b3f63ac40f6a3951d5e3148693b930c5f1beffb3dd9c50a3cc264706
7
+ data.tar.gz: b3c358a3a9e0c25d53667e37140f3d92c68a0be5b60dd0f32f80ad52e598789f93e657e804356fe0e204f2e973946ab6b55630ff6611cb6745f760aff728799c
@@ -208,7 +208,7 @@ module T::Private::Methods
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
210
  method_sig ||= T::Private::Methods._handle_missing_method_signature(
211
- is_singleton_method ? self.singleton_class : self.class,
211
+ self,
212
212
  original_method,
213
213
  __callee__,
214
214
  )
@@ -242,30 +242,40 @@ module T::Private::Methods
242
242
  end
243
243
  end
244
244
 
245
- def self._handle_missing_method_signature(klass, original_method, callee)
245
+ def self._handle_missing_method_signature(receiver, original_method, callee)
246
246
  method_sig = T::Private::Methods.signature_for_method(original_method)
247
-
248
- aliasing_method = klass.instance_method(callee)
249
- aliasing_mod = aliasing_method.owner
250
-
251
- if method_sig && aliasing_method != original_method && aliasing_method.original_name == original_method.name
252
- # We're handling a case where `alias` or `alias_method` was called for a
253
- # method which had already had a `sig` applied.
254
- #
255
- # Note, this logic is duplicated above, make sure to keep changes in sync.
256
- if method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
257
- # Checked, so copy the original signature to the aliased copy.
258
- T::Private::Methods.unwrap_method(aliasing_mod, method_sig, aliasing_method)
259
- else
260
- # Unchecked, so just make `alias_method` behave as if it had been called pre-sig.
261
- aliasing_mod.send(:alias_method, callee, original_method.name)
262
- end
263
- else
264
- 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. " \
265
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. " \
266
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."
267
251
  end
268
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
+
269
279
  method_sig
270
280
  end
271
281
 
@@ -287,7 +297,7 @@ module T::Private::Methods
287
297
  Signature.new_untyped(method: original_method)
288
298
  end
289
299
 
290
- unwrap_method(hook_mod, signature, original_method)
300
+ unwrap_method(signature.method.owner, signature, original_method)
291
301
  signature
292
302
  end
293
303
 
@@ -339,8 +349,8 @@ module T::Private::Methods
339
349
  end
340
350
  end
341
351
 
342
- def self.unwrap_method(hook_mod, signature, original_method)
343
- 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)
344
354
  @signatures_by_method[method_to_key(maybe_wrapped_method)] = signature
345
355
  end
346
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.5858
4
+ version: 0.5.5866
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-31 00:00:00.000000000 Z
11
+ date: 2020-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest