sorbet-runtime 0.5.6539 → 0.5.10400

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sorbet-runtime.rb +4 -2
  3. data/lib/types/_types.rb +20 -9
  4. data/lib/types/configuration.rb +89 -56
  5. data/lib/types/enum.rb +22 -16
  6. data/lib/types/generic.rb +2 -2
  7. data/lib/types/helpers.rb +12 -3
  8. data/lib/types/interface_wrapper.rb +8 -4
  9. data/lib/types/non_forcing_constants.rb +5 -9
  10. data/lib/types/private/abstract/data.rb +1 -1
  11. data/lib/types/private/abstract/declare.rb +5 -0
  12. data/lib/types/private/abstract/hooks.rb +1 -2
  13. data/lib/types/private/casts.rb +2 -10
  14. data/lib/types/private/class_utils.rb +23 -7
  15. data/lib/types/private/compiler.rb +24 -0
  16. data/lib/types/private/methods/_methods.rb +25 -19
  17. data/lib/types/private/methods/call_validation.rb +9 -13
  18. data/lib/types/private/methods/call_validation_2_6.rb +64 -64
  19. data/lib/types/private/methods/call_validation_2_7.rb +64 -64
  20. data/lib/types/private/methods/decl_builder.rb +5 -5
  21. data/lib/types/private/methods/modes.rb +18 -6
  22. data/lib/types/private/methods/signature.rb +11 -2
  23. data/lib/types/private/methods/signature_validation.rb +3 -4
  24. data/lib/types/private/runtime_levels.rb +7 -1
  25. data/lib/types/private/sealed.rb +27 -16
  26. data/lib/types/private/types/not_typed.rb +4 -4
  27. data/lib/types/private/types/string_holder.rb +3 -3
  28. data/lib/types/private/types/type_alias.rb +3 -3
  29. data/lib/types/private/types/void.rb +4 -4
  30. data/lib/types/props/_props.rb +21 -14
  31. data/lib/types/props/constructor.rb +1 -1
  32. data/lib/types/props/custom_type.rb +1 -1
  33. data/lib/types/props/decorator.rb +44 -54
  34. data/lib/types/props/generated_code_validation.rb +1 -1
  35. data/lib/types/props/has_lazily_specialized_methods.rb +6 -1
  36. data/lib/types/props/optional.rb +13 -5
  37. data/lib/types/props/private/serde_transform.rb +3 -3
  38. data/lib/types/props/private/serializer_generator.rb +0 -1
  39. data/lib/types/props/serializable.rb +34 -20
  40. data/lib/types/props/weak_constructor.rb +2 -2
  41. data/lib/types/struct.rb +33 -0
  42. data/lib/types/types/attached_class.rb +3 -3
  43. data/lib/types/types/base.rb +8 -2
  44. data/lib/types/types/class_of.rb +6 -4
  45. data/lib/types/types/enum.rb +5 -7
  46. data/lib/types/types/fixed_array.rb +5 -5
  47. data/lib/types/types/fixed_hash.rb +23 -17
  48. data/lib/types/types/intersection.rb +4 -4
  49. data/lib/types/types/noreturn.rb +3 -3
  50. data/lib/types/types/proc.rb +3 -3
  51. data/lib/types/types/self_type.rb +6 -6
  52. data/lib/types/types/simple.rb +32 -7
  53. data/lib/types/types/t_enum.rb +3 -3
  54. data/lib/types/types/type_variable.rb +4 -1
  55. data/lib/types/types/typed_array.rb +3 -3
  56. data/lib/types/types/typed_enumerable.rb +10 -5
  57. data/lib/types/types/typed_enumerator.rb +3 -3
  58. data/lib/types/types/typed_enumerator_lazy.rb +41 -0
  59. data/lib/types/types/typed_hash.rb +3 -3
  60. data/lib/types/types/typed_range.rb +3 -3
  61. data/lib/types/types/typed_set.rb +15 -3
  62. data/lib/types/types/union.rb +4 -4
  63. data/lib/types/types/untyped.rb +3 -3
  64. data/lib/types/utils.rb +9 -1
  65. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3594dc0c726d2a7189c7544226a6ced4240f4a6df2c18bdae635cc30bb223e7b
4
- data.tar.gz: dae60008d7f685ecdf231edefdf0b01b595c597c6ae646e7ba7070eada079fa2
3
+ metadata.gz: 93aad7f9ae5bc82ef7440bd821050e9d83993bc82c933871fea517b5f3bbcff3
4
+ data.tar.gz: f03d589b929263d8553cc27d73c83c9b131aafa0978cbabcbb2150d67548e164
5
5
  SHA512:
6
- metadata.gz: 519bf1b1c4f04792d88c817a9bb3a213b01e783a96597e1e328a8a5c9736e78ff7a0a93ef31d56787fd9468d09980e4670edffcd71f59ff299cc7a09a80a714b
7
- data.tar.gz: 0150d316fb26d07fd0693d3b948dfaa6fe1979053dc12f9811c5c9c6d29b711affaa3e6be16a34a08fd6abf5a1db816b4872b7b655895353cdf65094f7e0ad5c
6
+ metadata.gz: 4e8188a05baefa453694665587cc68859151ab9243da61a0a370a5aa767a35f719dda6b7b1e778bc9bd7fb67b53603cb73d0868f0d8a5dbfebe051e0e941a067
7
+ data.tar.gz: dc0fec301dfd6efec2e2f909eae36df55323881604b7a5635eb301e40748d532fca0000eb5ff213cced1b5318187dfb42940635ded58e9a88d0d7b6bdce92560
@@ -12,8 +12,6 @@ module T::Private; end
12
12
  module T::Private::Abstract; end
13
13
  module T::Private::Types; end
14
14
 
15
- require 'set'
16
-
17
15
  # Each section is a group that I believe need a fixed ordering. There is also
18
16
  # an ordering between groups.
19
17
 
@@ -47,6 +45,7 @@ require_relative 'types/types/t_enum'
47
45
  require_relative 'types/types/type_parameter'
48
46
  require_relative 'types/types/typed_array'
49
47
  require_relative 'types/types/typed_enumerator'
48
+ require_relative 'types/types/typed_enumerator_lazy'
50
49
  require_relative 'types/types/typed_hash'
51
50
  require_relative 'types/types/typed_range'
52
51
  require_relative 'types/types/typed_set'
@@ -112,3 +111,6 @@ require_relative 'types/struct'
112
111
  require_relative 'types/non_forcing_constants'
113
112
 
114
113
  require_relative 'types/compatibility_patches'
114
+
115
+ # Sorbet Compiler support module
116
+ require_relative 'types/private/compiler'
data/lib/types/_types.rb CHANGED
@@ -53,7 +53,8 @@ module T
53
53
  end
54
54
 
55
55
  # Matches any of the listed values
56
- def self.enum(values)
56
+ # @deprecated Use T::Enum instead.
57
+ def self.deprecated_enum(values)
57
58
  T::Types::Enum.new(values)
58
59
  end
59
60
 
@@ -78,14 +79,13 @@ module T
78
79
  T::Types::ClassOf.new(klass)
79
80
  end
80
81
 
81
-
82
82
  ## END OF THE METHODS TO PASS TO `sig`.
83
83
 
84
-
85
84
  # Constructs a type alias. Used to create a short name for a larger type. In Ruby this returns a
86
85
  # wrapper that contains a proc that is evaluated to get the underlying type. This syntax however
87
- # is needed for support by the static checker. Example usage:
86
+ # is needed for support by the static checker.
88
87
  #
88
+ # @example
89
89
  # NilableString = T.type_alias {T.nilable(String)}
90
90
  #
91
91
  # sig {params(arg: NilableString, default: String).returns(String)}
@@ -108,8 +108,9 @@ module T
108
108
  # References a type parameter which was previously defined with
109
109
  # `type_parameters`.
110
110
  #
111
- # This is used for generic methods. Example usage:
111
+ # This is used for generic methods.
112
112
  #
113
+ # @example
113
114
  # sig
114
115
  # .type_parameters(:U)
115
116
  # .params(
@@ -187,7 +188,7 @@ module T
187
188
  # cycle. However, we also don't actually need to do so; An untyped
188
189
  # identity method works just as well here.
189
190
  #
190
- # sig {params(value: T.untyped).returns(T.untyped)}
191
+ # `sig {params(value: T.untyped).returns(T.untyped)}`
191
192
  def self.unsafe(value)
192
193
  value
193
194
  end
@@ -208,7 +209,7 @@ module T
208
209
  # Intended to be used to promise sorbet that a given nilable value happens
209
210
  # to contain a non-nil value at this point.
210
211
  #
211
- # sig {params(arg: T.nilable(A)).returns(A)}
212
+ # `sig {params(arg: T.nilable(A)).returns(A)}`
212
213
  def self.must(arg)
213
214
  return arg if arg
214
215
  return arg if arg == false
@@ -216,7 +217,7 @@ module T
216
217
  begin
217
218
  raise TypeError.new("Passed `nil` into T.must")
218
219
  rescue TypeError => e # raise into rescue to ensure e.backtrace is populated
219
- T::Configuration.inline_type_error_handler(e)
220
+ T::Configuration.inline_type_error_handler(e, {kind: 'T.must', value: arg, type: nil})
220
221
  end
221
222
  end
222
223
 
@@ -241,7 +242,7 @@ module T
241
242
  begin
242
243
  raise TypeError.new(msg)
243
244
  rescue TypeError => e # raise into rescue to ensure e.backtrace is populated
244
- T::Configuration.inline_type_error_handler(e)
245
+ T::Configuration.inline_type_error_handler(e, {kind: 'T.absurd', value: value, type: nil})
245
246
  end
246
247
  end
247
248
 
@@ -285,6 +286,16 @@ module T
285
286
  T::Types::TypedEnumerator.new(type)
286
287
  end
287
288
  end
289
+
290
+ module Lazy
291
+ def self.[](type)
292
+ if type.is_a?(T::Types::Untyped)
293
+ T::Types::TypedEnumeratorLazy::Untyped.new
294
+ else
295
+ T::Types::TypedEnumeratorLazy.new(type)
296
+ end
297
+ end
298
+ end
288
299
  end
289
300
 
290
301
  module Range
@@ -80,6 +80,7 @@ module T::Configuration
80
80
  T::Props::Private::DeserializerGenerator.respond_to?(:generate2)
81
81
  end
82
82
 
83
+ @use_vm_prop_serde = false
83
84
  # Whether to use VM-defined prop serialization/deserialization routines.
84
85
  #
85
86
  # The default is to use runtime codegen inside sorbet-runtime itself.
@@ -112,11 +113,12 @@ module T::Configuration
112
113
  # statically, so that methods don't have to guard themselves from being
113
114
  # called incorrectly by untyped code.
114
115
  #
115
- # @param [:never, :tests, :always] default_checked_level
116
+ # @param [:never, :compiled, :tests, :always] default_checked_level
116
117
  def self.default_checked_level=(default_checked_level)
117
118
  T::Private::RuntimeLevels.default_checked_level = default_checked_level
118
119
  end
119
120
 
121
+ @inline_type_error_handler = nil
120
122
  # Set a handler to handle `TypeError`s raised by any in-line type assertions,
121
123
  # including `T.must`, `T.let`, `T.cast`, and `T.assert_type!`.
122
124
  #
@@ -130,10 +132,15 @@ module T::Configuration
130
132
  #
131
133
  # Parameters passed to value.call:
132
134
  #
133
- # @param [TypeError] error TypeError that was raised
135
+ # @param [TypeError] error TypeError that was raised
136
+ # @param [Hash] opts A hash containing contextual information on the error:
137
+ # @option opts [String] :kind One of:
138
+ # ['T.cast', 'T.let', 'T.bind', 'T.assert_type!', 'T.must', 'T.absurd']
139
+ # @option opts [Object, nil] :type Expected param/return value type
140
+ # @option opts [Object] :value Actual param/return value
134
141
  #
135
142
  # @example
136
- # T::Configuration.inline_type_error_handler = lambda do |error|
143
+ # T::Configuration.inline_type_error_handler = lambda do |error, opts|
137
144
  # puts error.message
138
145
  # end
139
146
  def self.inline_type_error_handler=(value)
@@ -141,19 +148,25 @@ module T::Configuration
141
148
  @inline_type_error_handler = value
142
149
  end
143
150
 
144
- private_class_method def self.inline_type_error_handler_default(error)
151
+ private_class_method def self.inline_type_error_handler_default(error, opts)
145
152
  raise error
146
153
  end
147
154
 
148
- def self.inline_type_error_handler(error)
155
+ def self.inline_type_error_handler(error, opts={})
149
156
  if @inline_type_error_handler
150
- @inline_type_error_handler.call(error)
157
+ # Backwards compatibility before `inline_type_error_handler` took a second arg
158
+ if @inline_type_error_handler.arity == 1
159
+ @inline_type_error_handler.call(error)
160
+ else
161
+ @inline_type_error_handler.call(error, opts)
162
+ end
151
163
  else
152
- inline_type_error_handler_default(error)
164
+ inline_type_error_handler_default(error, opts)
153
165
  end
154
166
  nil
155
167
  end
156
168
 
169
+ @sig_builder_error_handler = nil
157
170
  # Set a handler to handle errors that occur when the builder methods in the
158
171
  # body of a sig are executed. The sig builder methods are inside a proc so
159
172
  # that they can be lazily evaluated the first time the method being sig'd is
@@ -169,8 +182,8 @@ module T::Configuration
169
182
  #
170
183
  # Parameters passed to value.call:
171
184
  #
172
- # @param [StandardError] error The error that was raised
173
- # @param [Thread::Backtrace::Location] location Location of the error
185
+ # @param [StandardError] error The error that was raised
186
+ # @param [Thread::Backtrace::Location] location Location of the error
174
187
  #
175
188
  # @example
176
189
  # T::Configuration.sig_builder_error_handler = lambda do |error, location|
@@ -194,6 +207,7 @@ module T::Configuration
194
207
  nil
195
208
  end
196
209
 
210
+ @sig_validation_error_handler = nil
197
211
  # Set a handler to handle sig validation errors.
198
212
  #
199
213
  # Sig validation errors include things like abstract checks, override checks,
@@ -211,16 +225,16 @@ module T::Configuration
211
225
  #
212
226
  # Parameters passed to value.call:
213
227
  #
214
- # @param [StandardError] error The error that was raised
215
- # @param [Hash] opts A hash containing contextual information on the error:
216
- # @option opts [Method, UnboundMethod] :method Method on which the signature build failed
217
- # @option opts [T::Private::Methods::Declaration] :declaration Method
218
- # signature declaration struct
219
- # @option opts [T::Private::Methods::Signature, nil] :signature Signature
220
- # that failed (nil if sig build failed before Signature initialization)
221
- # @option opts [T::Private::Methods::Signature, nil] :super_signature Super
222
- # method's signature (nil if method is not an override or super method
223
- # does not have a method signature)
228
+ # @param [StandardError] error The error that was raised
229
+ # @param [Hash] opts A hash containing contextual information on the error:
230
+ # @option opts [Method, UnboundMethod] :method Method on which the signature build failed
231
+ # @option opts [T::Private::Methods::Declaration] :declaration Method
232
+ # signature declaration struct
233
+ # @option opts [T::Private::Methods::Signature, nil] :signature Signature
234
+ # that failed (nil if sig build failed before Signature initialization)
235
+ # @option opts [T::Private::Methods::Signature, nil] :super_signature Super
236
+ # method's signature (nil if method is not an override or super method
237
+ # does not have a method signature)
224
238
  #
225
239
  # @example
226
240
  # T::Configuration.sig_validation_error_handler = lambda do |error, opts|
@@ -244,6 +258,7 @@ module T::Configuration
244
258
  nil
245
259
  end
246
260
 
261
+ @call_validation_error_handler = nil
247
262
  # Set a handler for type errors that result from calling a method.
248
263
  #
249
264
  # By default, errors from calling a method cause an exception to be raised.
@@ -256,17 +271,17 @@ module T::Configuration
256
271
  #
257
272
  # Parameters passed to value.call:
258
273
  #
259
- # @param [T::Private::Methods::Signature] signature Signature that failed
260
- # @param [Hash] opts A hash containing contextual information on the error:
261
- # @option opts [String] :message Error message
262
- # @option opts [String] :kind One of:
263
- # ['Parameter', 'Block parameter', 'Return value']
264
- # @option opts [Symbol] :name Param or block param name (nil for return
265
- # value)
266
- # @option opts [Object] :type Expected param/return value type
267
- # @option opts [Object] :value Actual param/return value
268
- # @option opts [Thread::Backtrace::Location] :location Location of the
269
- # caller
274
+ # @param [T::Private::Methods::Signature] signature Signature that failed
275
+ # @param [Hash] opts A hash containing contextual information on the error:
276
+ # @option opts [String] :message Error message
277
+ # @option opts [String] :kind One of:
278
+ # ['Parameter', 'Block parameter', 'Return value']
279
+ # @option opts [Symbol] :name Param or block param name (nil for return
280
+ # value)
281
+ # @option opts [Object] :type Expected param/return value type
282
+ # @option opts [Object] :value Actual param/return value
283
+ # @option opts [Thread::Backtrace::Location] :location Location of the
284
+ # caller
270
285
  #
271
286
  # @example
272
287
  # T::Configuration.call_validation_error_handler = lambda do |signature, opts|
@@ -290,6 +305,7 @@ module T::Configuration
290
305
  nil
291
306
  end
292
307
 
308
+ @log_info_handler = nil
293
309
  # Set a handler for logging
294
310
  #
295
311
  # @param [Lambda, Proc, Object, nil] value Proc that handles the error
@@ -297,8 +313,8 @@ module T::Configuration
297
313
  #
298
314
  # Parameters passed to value.call:
299
315
  #
300
- # @param [String] str Message to be logged
301
- # @param [Hash] extra A hash containing additional parameters to be passed along to the logger.
316
+ # @param [String] str Message to be logged
317
+ # @param [Hash] extra A hash containing additional parameters to be passed along to the logger.
302
318
  #
303
319
  # @example
304
320
  # T::Configuration.log_info_handler = lambda do |str, extra|
@@ -321,6 +337,7 @@ module T::Configuration
321
337
  end
322
338
  end
323
339
 
340
+ @soft_assert_handler = nil
324
341
  # Set a handler for soft assertions
325
342
  #
326
343
  # These generally shouldn't stop execution of the program, but rather inform
@@ -331,8 +348,8 @@ module T::Configuration
331
348
  #
332
349
  # Parameters passed to value.call:
333
350
  #
334
- # @param [String] str Assertion message
335
- # @param [Hash] extra A hash containing additional parameters to be passed along to the handler.
351
+ # @param [String] str Assertion message
352
+ # @param [Hash] extra A hash containing additional parameters to be passed along to the handler.
336
353
  #
337
354
  # @example
338
355
  # T::Configuration.soft_assert_handler = lambda do |str, extra|
@@ -355,6 +372,7 @@ module T::Configuration
355
372
  end
356
373
  end
357
374
 
375
+ @hard_assert_handler = nil
358
376
  # Set a handler for hard assertions
359
377
  #
360
378
  # These generally should stop execution of the program, and optionally inform
@@ -365,8 +383,8 @@ module T::Configuration
365
383
  #
366
384
  # Parameters passed to value.call:
367
385
  #
368
- # @param [String] str Assertion message
369
- # @param [Hash] extra A hash containing additional parameters to be passed along to the handler.
386
+ # @param [String] str Assertion message
387
+ # @param [Hash] extra A hash containing additional parameters to be passed along to the handler.
370
388
  #
371
389
  # @example
372
390
  # T::Configuration.hard_assert_handler = lambda do |str, extra|
@@ -389,10 +407,11 @@ module T::Configuration
389
407
  end
390
408
  end
391
409
 
410
+ @scalar_types = nil
392
411
  # Set a list of class strings that are to be considered scalar.
393
412
  # (pass nil to reset to default behavior)
394
413
  #
395
- # @param [String] value Class name.
414
+ # @param [String] values Class name.
396
415
  #
397
416
  # @example
398
417
  # T::Configuration.scalar_types = ["NilClass", "TrueClass", "FalseClass", ...]
@@ -405,21 +424,21 @@ module T::Configuration
405
424
  raise ArgumentError.new("Provided values must all be class name strings.")
406
425
  end
407
426
 
408
- @scalar_types = Set.new(values).freeze
427
+ @scalar_types = values.each_with_object({}) {|x, acc| acc[x] = true}.freeze
409
428
  end
410
429
  end
411
430
 
412
- @default_scalar_types = Set.new(%w[
413
- NilClass
414
- TrueClass
415
- FalseClass
416
- Integer
417
- Float
418
- String
419
- Symbol
420
- Time
421
- T::Enum
422
- ]).freeze
431
+ @default_scalar_types = {
432
+ "NilClass" => true,
433
+ "TrueClass" => true,
434
+ "FalseClass" => true,
435
+ "Integer" => true,
436
+ "Float" => true,
437
+ "String" => true,
438
+ "Symbol" => true,
439
+ "Time" => true,
440
+ "T::Enum" => true,
441
+ }.freeze
423
442
 
424
443
  def self.scalar_types
425
444
  @scalar_types || @default_scalar_types
@@ -429,10 +448,10 @@ module T::Configuration
429
448
  MODULE_NAME = Module.instance_method(:name)
430
449
  private_constant :MODULE_NAME
431
450
 
432
- if T::Configuration::AT_LEAST_RUBY_2_7
433
- @default_module_name_mangler = ->(type) {MODULE_NAME.bind_call(type)}
451
+ @default_module_name_mangler = if T::Configuration::AT_LEAST_RUBY_2_7
452
+ ->(type) {MODULE_NAME.bind_call(type)}
434
453
  else
435
- @default_module_name_mangler = ->(type) {MODULE_NAME.bind(type).call}
454
+ ->(type) {MODULE_NAME.bind(type).call}
436
455
  end
437
456
 
438
457
  @module_name_mangler = nil
@@ -445,16 +464,17 @@ module T::Configuration
445
464
  # to names in generated code. Used by the runtime implementation
446
465
  # associated with `--stripe-packages` mode.
447
466
  #
448
- # @param [Lambda, Proc, nil] value Proc that converts a type (Class/Module)
467
+ # @param [Lambda, Proc, nil] handler Proc that converts a type (Class/Module)
449
468
  # to a String (pass nil to reset to default behavior)
450
469
  def self.module_name_mangler=(handler)
451
470
  @module_name_mangler = handler
452
471
  end
453
472
 
473
+ @sensitivity_and_pii_handler = nil
454
474
  # Set to a PII handler function. This will be called with the `sensitivity:`
455
475
  # annotations on things that use `T::Props` and can modify them ahead-of-time.
456
476
  #
457
- # @param [Lambda, Proc, nil] value Proc that takes a hash mapping symbols to the
477
+ # @param [Lambda, Proc, nil] handler Proc that takes a hash mapping symbols to the
458
478
  # prop values. Pass nil to avoid changing `sensitivity:` annotations.
459
479
  def self.normalize_sensitivity_and_pii_handler=(handler)
460
480
  @sensitivity_and_pii_handler = handler
@@ -470,7 +490,7 @@ module T::Configuration
470
490
  # `nil` and will raise an exception when the redacted version of a prop is
471
491
  # accessed.
472
492
  #
473
- # @param [Lambda, Proc, nil] value Proc that converts a value into its
493
+ # @param [Lambda, Proc, nil] handler Proc that converts a value into its
474
494
  # redacted version according to the spec passed as the second argument.
475
495
  def self.redaction_handler=(handler)
476
496
  @redaction_handler = handler
@@ -480,10 +500,11 @@ module T::Configuration
480
500
  @redaction_handler
481
501
  end
482
502
 
503
+ @class_owner_finder = nil
483
504
  # Set to a function which can get the 'owner' of a class. This is
484
505
  # used in reporting deserialization errors
485
506
  #
486
- # @param [Lambda, Proc, nil] value Proc that takes a class and
507
+ # @param [Lambda, Proc, nil] handler Proc that takes a class and
487
508
  # produces its owner, or `nil` if it does not have one.
488
509
  def self.class_owner_finder=(handler)
489
510
  @class_owner_finder = handler
@@ -513,6 +534,7 @@ module T::Configuration
513
534
  end
514
535
  end
515
536
 
537
+ @legacy_t_enum_migration_mode = false
516
538
  def self.enable_legacy_t_enum_migration_mode
517
539
  @legacy_t_enum_migration_mode = true
518
540
  end
@@ -523,6 +545,17 @@ module T::Configuration
523
545
  @legacy_t_enum_migration_mode || false
524
546
  end
525
547
 
548
+ @prop_freeze_handler = ->(instance, prop_name) {}
549
+
550
+ def self.prop_freeze_handler=(handler)
551
+ @prop_freeze_handler = handler
552
+ end
553
+
554
+ def self.prop_freeze_handler
555
+ @prop_freeze_handler
556
+ end
557
+
558
+ @sealed_violation_whitelist = nil
526
559
  # @param [Array] sealed_violation_whitelist An array of Regexp to validate
527
560
  # whether inheriting /including a sealed module outside the defining module
528
561
  # should be allowed. Useful to whitelist benign violations, like shim files
data/lib/types/enum.rb CHANGED
@@ -47,7 +47,7 @@ class T::Enum
47
47
  SerializedVal = T.type_alias {T.untyped}
48
48
  private_constant :SerializedVal
49
49
 
50
- ## Enum class methods ##
50
+ ### Enum class methods ###
51
51
  sig {returns(T::Array[T.attached_class])}
52
52
  def self.values
53
53
  if @values.nil?
@@ -134,9 +134,7 @@ class T::Enum
134
134
  self.from_serialized(mongo_value)
135
135
  end
136
136
 
137
-
138
- ## Enum instance methods ##
139
-
137
+ ### Enum instance methods ###
140
138
 
141
139
  sig {returns(T.self_type)}
142
140
  def dup
@@ -160,6 +158,13 @@ class T::Enum
160
158
  serialize.to_json(*args)
161
159
  end
162
160
 
161
+ sig {params(args: T.untyped).returns(T.untyped)}
162
+ def as_json(*args)
163
+ serialized_val = serialize
164
+ return serialized_val unless serialized_val.respond_to?(:as_json)
165
+ serialized_val.as_json(*args)
166
+ end
167
+
163
168
  sig {returns(String)}
164
169
  def to_s
165
170
  inspect
@@ -180,7 +185,6 @@ class T::Enum
180
185
  end
181
186
  end
182
187
 
183
-
184
188
  # NB: Do not call this method. This exists to allow for a safe migration path in places where enum
185
189
  # values are compared directly against string values.
186
190
  #
@@ -246,9 +250,7 @@ class T::Enum
246
250
  )
247
251
  end
248
252
 
249
-
250
- ## Private implementation ##
251
-
253
+ ### Private implementation ###
252
254
 
253
255
  sig {params(serialized_val: SerializedVal).void}
254
256
  def initialize(serialized_val=nil)
@@ -286,19 +288,23 @@ class T::Enum
286
288
  # Historical note: We convert to lowercase names because the majority of existing calls to
287
289
  # `make_accessible` were arrays of lowercase strings. Doing this conversion allowed for the
288
290
  # least amount of repetition in migrated declarations.
289
- const_name.to_s.downcase.freeze
291
+ -const_name.to_s.downcase.freeze
290
292
  end
291
293
 
292
294
  sig {returns(T::Boolean)}
293
295
  def self.started_initializing?
294
- @started_initializing = T.let(@started_initializing, T.nilable(T::Boolean))
295
- @started_initializing ||= false
296
+ unless defined?(@started_initializing)
297
+ @started_initializing = T.let(false, T.nilable(T::Boolean))
298
+ end
299
+ T.must(@started_initializing)
296
300
  end
297
301
 
298
302
  sig {returns(T::Boolean)}
299
303
  def self.fully_initialized?
300
- @fully_initialized = T.let(@fully_initialized, T.nilable(T::Boolean))
301
- @fully_initialized ||= false
304
+ unless defined?(@fully_initialized)
305
+ @fully_initialized = T.let(false, T.nilable(T::Boolean))
306
+ end
307
+ T.must(@fully_initialized)
302
308
  end
303
309
 
304
310
  # Maintains the order in which values are defined
@@ -313,8 +319,8 @@ class T::Enum
313
319
  sig {params(blk: T.proc.void).void}
314
320
  def self.enums(&blk)
315
321
  raise "enums cannot be defined for T::Enum" if self == T::Enum
316
- raise "Enum #{self} was already initialized" if @fully_initialized
317
- raise "Enum #{self} is still initializing" if @started_initializing
322
+ raise "Enum #{self} was already initialized" if fully_initialized?
323
+ raise "Enum #{self} is still initializing" if started_initializing?
318
324
 
319
325
  @started_initializing = true
320
326
 
@@ -366,6 +372,6 @@ class T::Enum
366
372
 
367
373
  sig {params(args: String).returns(T.attached_class)}
368
374
  def self._load(args)
369
- deserialize(Marshal.load(args))
375
+ deserialize(Marshal.load(args)) # rubocop:disable Security/MarshalLoad
370
376
  end
371
377
  end
data/lib/types/generic.rb CHANGED
@@ -12,11 +12,11 @@ module T::Generic
12
12
  self
13
13
  end
14
14
 
15
- def type_member(variance=:invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
15
+ def type_member(variance=:invariant, &blk)
16
16
  T::Types::TypeMember.new(variance)
17
17
  end
18
18
 
19
- def type_template(variance=:invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
19
+ def type_template(variance=:invariant, &blk)
20
20
  T::Types::TypeTemplate.new(variance)
21
21
  end
22
22
  end
data/lib/types/helpers.rb CHANGED
@@ -2,13 +2,22 @@
2
2
  # typed: true
3
3
 
4
4
  # Use as a mixin with extend (`extend T::Helpers`).
5
- # Docs at https://confluence.corp.stripe.com/display/PRODINFRA/Ruby+Types
5
+ # Docs at https://sorbet.org/docs/
6
6
  module T::Helpers
7
+ extend T::Sig
8
+
7
9
  Private = T::Private
8
10
 
9
11
  ### Class/Module Helpers ###
10
12
 
11
13
  def abstract!
14
+ if defined?(super)
15
+ # This is to play nicely with Rails' AbstractController::Base,
16
+ # which also defines an `abstract!` method.
17
+ # https://api.rubyonrails.org/classes/AbstractController/Base.html#method-c-abstract-21
18
+ super
19
+ end
20
+
12
21
  Private::Abstract::Declare.declare_abstract(self, type: :abstract)
13
22
  end
14
23
 
@@ -44,7 +53,7 @@ module T::Helpers
44
53
  # module MyHelper
45
54
  # extend T::Helpers
46
55
  #
47
- # requires_ancestor Kernel
56
+ # requires_ancestor { Kernel }
48
57
  # end
49
58
  #
50
59
  # class MyClass < BasicObject # error: `MyClass` must include `Kernel` (required by `MyHelper`)
@@ -52,5 +61,5 @@ module T::Helpers
52
61
  # end
53
62
  #
54
63
  # TODO: implement the checks in sorbet-runtime.
55
- def requires_ancestor(mod, *mods); end
64
+ def requires_ancestor(&block); end
56
65
  end
@@ -43,17 +43,17 @@ class T::InterfaceWrapper
43
43
  def initialize(target_obj, interface_mod)
44
44
  if target_obj.is_a?(T::InterfaceWrapper)
45
45
  # wrapped_dynamic_cast should guarantee this never happens.
46
- raise "Unexpected: wrapping a wrapper. Please report to #dev-productivity."
46
+ raise "Unexpected: wrapping a wrapper. Please report this bug at https://github.com/sorbet/sorbet/issues"
47
47
  end
48
48
 
49
49
  if !target_obj.is_a?(interface_mod)
50
50
  # wrapped_dynamic_cast should guarantee this never happens.
51
- raise "Unexpected: `is_a?` failed. Please report to #dev-productivity."
51
+ raise "Unexpected: `is_a?` failed. Please report this bug at https://github.com/sorbet/sorbet/issues"
52
52
  end
53
53
 
54
54
  if target_obj.class == interface_mod
55
55
  # wrapped_dynamic_cast should guarantee this never happens.
56
- raise "Unexpected: exact class match. Please report to #dev-productivity."
56
+ raise "Unexpected: exact class match. Please report this bug at https://github.com/sorbet/sorbet/issues"
57
57
  end
58
58
 
59
59
  @target_obj = target_obj
@@ -71,6 +71,10 @@ class T::InterfaceWrapper
71
71
  target_obj.send(method_name, *args, &blk)
72
72
  end
73
73
 
74
+ if singleton_class.respond_to?(:ruby2_keywords, true)
75
+ singleton_class.send(:ruby2_keywords, method_name)
76
+ end
77
+
74
78
  if target_obj.singleton_class.public_method_defined?(method_name)
75
79
  # no-op, it's already public
76
80
  elsif target_obj.singleton_class.protected_method_defined?(method_name)
@@ -78,7 +82,7 @@ class T::InterfaceWrapper
78
82
  elsif target_obj.singleton_class.private_method_defined?(method_name)
79
83
  singleton_class.send(:private, method_name)
80
84
  else
81
- raise "This should never happen. Report to #dev-productivity"
85
+ raise "This should never happen. Report this bug at https://github.com/sorbet/sorbet/issues"
82
86
  end
83
87
  end
84
88
  end
@@ -2,11 +2,6 @@
2
2
  # typed: strict
3
3
 
4
4
  module T::NonForcingConstants
5
- T::Sig::WithoutRuntime.sig {returns(T::Boolean)}
6
- private_class_method def self.stripe_packages_enabled?
7
- const_defined?('StripePackages') && const_get('StripePackages').enabled?
8
- end
9
-
10
5
  # NOTE: This method is documented on the RBI in Sorbet's payload, so that it
11
6
  # shows up in the hover/completion documentation via LSP.
12
7
  T::Sig::WithoutRuntime.sig {params(val: BasicObject, klass: String, package: T.nilable(String)).returns(T::Boolean)}
@@ -16,10 +11,11 @@ module T::NonForcingConstants
16
11
  raise ArgumentError.new("The string given to `#{method_name}` must not be empty")
17
12
  end
18
13
 
19
- # TODO(gdritter): this might not be want we want in a multipackage
20
- # world; revisit this implementation we move on from the monopackage
21
- if stripe_packages_enabled?
22
- klass = "PkgRegistry::#{package}::#{klass}"
14
+ # We don't treat packages differently at runtime, but the static
15
+ # type-checker still needs to have the package and constant
16
+ # separated out. This just re-assembles the string as needed
17
+ if !package.nil?
18
+ klass = "::#{package}::#{klass}"
23
19
  end
24
20
 
25
21
  current_klass = T.let(nil, T.nilable(Module))