sorbet-runtime 0.5.5845 → 0.5.5858

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: 7ed7cf6960b963bcdb3578b9c02558381dc17b409ac335e47737aa2c01f2bab9
4
- data.tar.gz: da99d802502bbb2b64d6360bd2773559033dab41062e9ffbcc01699d55b8bc15
3
+ metadata.gz: ddae56dee53b7a4ae6c91b0ff2a279c9238255402a97a12d5c1cff9efd6e5777
4
+ data.tar.gz: 8de90de6b27854ae87ac9671d799e7d2fa2a2b4a4bde1a18d1574975b47f34a3
5
5
  SHA512:
6
- metadata.gz: 84445df7b4c62dc7f2770c0751c4b5aa9ab67e4dd00e6df257497eb59dc6d399a0576154b221509e576a96ad2953e20b87509a3f229f691a088178163b5ff286
7
- data.tar.gz: 14021ce8b6add25886a802dc6ace9cd4eb4d7495e8d44239ebf573aa2a5d27cdd97e579a0ee752e27afe10f0b5b6207e96c898b9000b7986869cba2f0904f109
6
+ metadata.gz: 33be9484fb679eacae0992574ff30492e4549ae0a63a4c17d3348bf7e514bf6f62162f58290c6b9a674e38a27343be3a13f9b9bdcd20d99d804a47719bf4206c
7
+ data.tar.gz: 560140944b988f084d31c7b04ff32d9f8a02f87e6a0a99d3956493f0cf7ae87fad51f032b0aced1ba6a48bf1eaa7c1b89bfc15a10330c752229dc541a2b4ae17
@@ -206,22 +206,12 @@ module T::Private::Methods
206
206
  # (or unwrap back to the original method).
207
207
  new_method = nil
208
208
  T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
209
- if !T::Private::Methods.has_sig_block_for_method(new_method)
210
- # This should only happen if the user used alias_method to grab a handle
211
- # to the original pre-unwound `sig` method. I guess we'll just proxy the
212
- # call forever since we don't know who is holding onto this handle to
213
- # replace it.
214
- new_new_method = mod.instance_method(method_name)
215
- if new_method == new_new_method
216
- raise "`sig` not present for method `#{method_name}` but you're trying to run it anyways. " \
217
- "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. " \
218
- "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. " \
219
- "Contact #dev-productivity if you're really stuck."
220
- end
221
- return new_new_method.bind(self).call(*args, &blk)
222
- end
223
-
224
- method_sig = T::Private::Methods.run_sig_block_for_method(new_method)
209
+ method_sig = T::Private::Methods.maybe_run_sig_block_for_method(new_method)
210
+ method_sig ||= T::Private::Methods._handle_missing_method_signature(
211
+ is_singleton_method ? self.singleton_class : self.class,
212
+ original_method,
213
+ __callee__,
214
+ )
225
215
 
226
216
  # Should be the same logic as CallValidation.wrap_method_if_needed but we
227
217
  # don't want that extra layer of indirection in the callstack
@@ -252,6 +242,33 @@ module T::Private::Methods
252
242
  end
253
243
  end
254
244
 
245
+ def self._handle_missing_method_signature(klass, original_method, callee)
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. " \
265
+ "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
+ "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
+ end
268
+
269
+ method_sig
270
+ end
271
+
255
272
  # Executes the `sig` block, and converts the resulting Declaration
256
273
  # to a Signature.
257
274
  def self.run_sig(hook_mod, method_name, original_method, declaration_block)
@@ -146,9 +146,10 @@ class T::Private::Methods::Signature
146
146
  # can't) match the definition of the method we're validating. In addition, Ruby has a bug that
147
147
  # causes forwarding **kwargs to do the wrong thing: see https://bugs.ruby-lang.org/issues/10708
148
148
  # and https://bugs.ruby-lang.org/issues/11860.
149
- if (args.length > @req_arg_count) && (!@kwarg_types.empty? || @has_keyrest) && args[-1].is_a?(Hash)
149
+ args_length = args.length
150
+ if (args_length > @req_arg_count) && (!@kwarg_types.empty? || @has_keyrest) && args[-1].is_a?(Hash)
150
151
  kwargs = args[-1]
151
- args = args[0...-1]
152
+ args_length -= 1
152
153
  else
153
154
  kwargs = EMPTY_HASH
154
155
  end
@@ -156,19 +157,19 @@ class T::Private::Methods::Signature
156
157
  arg_types = @arg_types
157
158
 
158
159
  if @has_rest
159
- arg_types += [[@rest_name, @rest_type]] * (args.length - @arg_types.length)
160
+ arg_types += [[@rest_name, @rest_type]] * (args_length - @arg_types.length)
160
161
 
161
- elsif (args.length < @req_arg_count) || (args.length > @arg_types.length)
162
+ elsif (args_length < @req_arg_count) || (args_length > @arg_types.length)
162
163
  expected_str = @req_arg_count.to_s
163
164
  if @arg_types.length != @req_arg_count
164
165
  expected_str += "..#{@arg_types.length}"
165
166
  end
166
- raise ArgumentError.new("wrong number of arguments (given #{args.length}, expected #{expected_str})")
167
+ raise ArgumentError.new("wrong number of arguments (given #{args_length}, expected #{expected_str})")
167
168
  end
168
169
 
169
170
  begin
170
171
  it = 0
171
- while it < args.length
172
+ while it < args_length
172
173
  yield arg_types[it][0], args[it], arg_types[it][1]
173
174
  it += 1
174
175
  end
@@ -12,7 +12,11 @@ module T::Types
12
12
 
13
13
  # @override Base
14
14
  def name
15
- @raw_type.name
15
+ # Memoize to mitigate pathological performance with anonymous modules (https://bugs.ruby-lang.org/issues/11119)
16
+ #
17
+ # `name` isn't normally a hot path for types, but it is used in initializing a T::Types::Union,
18
+ # and so in `T.nilable`, and so in runtime constructions like `x = T.let(nil, T.nilable(Integer))`.
19
+ @name ||= @raw_type.name.freeze
16
20
  end
17
21
 
18
22
  # @override Base
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.5845
4
+ version: 0.5.5858
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-24 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest