sorbet-runtime 0.5.9889 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a7a3fab5ea8600237fa39e859be1e28620584bb1b58349d049e0f5e03146dc1
4
- data.tar.gz: 4ae6ef0d6b43dc1205d5a54f141c5a4775eaecacae3b37c1d89dbc32a259d702
3
+ metadata.gz: 93aad7f9ae5bc82ef7440bd821050e9d83993bc82c933871fea517b5f3bbcff3
4
+ data.tar.gz: f03d589b929263d8553cc27d73c83c9b131aafa0978cbabcbb2150d67548e164
5
5
  SHA512:
6
- metadata.gz: 72c661853dc7f8b7243d7b37cc5868c1bb962df3b6df38b8c5d1f8345751bdea0bb69bc15f5eb5dbb1dde132da4720afe0ee87cf112dcd2e33cbd6264f704ecb
7
- data.tar.gz: 2d9060c44a422f615c44d1cbc61e24f051f7087c3e18552b5fd702f99649c85eb12276cce7186d2ecf5c2b97f269fe0a503edde775ff94d6d6b2cd9dc1bb781c
6
+ metadata.gz: 4e8188a05baefa453694665587cc68859151ab9243da61a0a370a5aa767a35f719dda6b7b1e778bc9bd7fb67b53603cb73d0868f0d8a5dbfebe051e0e941a067
7
+ data.tar.gz: dc0fec301dfd6efec2e2f909eae36df55323881604b7a5635eb301e40748d532fca0000eb5ff213cced1b5318187dfb42940635ded58e9a88d0d7b6bdce92560
data/lib/types/enum.rb CHANGED
@@ -158,6 +158,13 @@ class T::Enum
158
158
  serialize.to_json(*args)
159
159
  end
160
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
+
161
168
  sig {returns(String)}
162
169
  def to_s
163
170
  inspect
@@ -281,7 +288,7 @@ class T::Enum
281
288
  # Historical note: We convert to lowercase names because the majority of existing calls to
282
289
  # `make_accessible` were arrays of lowercase strings. Doing this conversion allowed for the
283
290
  # least amount of repetition in migrated declarations.
284
- const_name.to_s.downcase.freeze
291
+ -const_name.to_s.downcase.freeze
285
292
  end
286
293
 
287
294
  sig {returns(T::Boolean)}
data/lib/types/generic.rb CHANGED
@@ -12,13 +12,11 @@ module T::Generic
12
12
  self
13
13
  end
14
14
 
15
- # TODO(jez) Remove these keyword arguments once it's a static error
16
- def type_member(variance=:invariant, fixed: nil, lower: T.untyped, upper: BasicObject, &blk)
15
+ def type_member(variance=:invariant, &blk)
17
16
  T::Types::TypeMember.new(variance)
18
17
  end
19
18
 
20
- # TODO(jez) Remove these keyword arguments once it's a static error
21
- def type_template(variance=:invariant, fixed: nil, lower: T.untyped, upper: BasicObject, &blk)
19
+ def type_template(variance=:invariant, &blk)
22
20
  T::Types::TypeTemplate.new(variance)
23
21
  end
24
22
  end
data/lib/types/helpers.rb CHANGED
@@ -2,7 +2,7 @@
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
7
  extend T::Sig
8
8
 
@@ -11,6 +11,13 @@ module T::Helpers
11
11
  ### Class/Module Helpers ###
12
12
 
13
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
+
14
21
  Private::Abstract::Declare.declare_abstract(self, type: :abstract)
15
22
  end
16
23
 
@@ -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)
@@ -69,6 +69,27 @@ module T::Private::ClassUtils
69
69
  end
70
70
  end
71
71
 
72
+ def self.def_with_visibility(mod, name, visibility, method=nil, &block)
73
+ mod.module_exec do
74
+ # Start a visibility (public/protected/private) region, so that
75
+ # all of the method redefinitions happen with the right visibility
76
+ # from the beginning. This ensures that any other code that is
77
+ # triggered by `method_added`, sees the redefined method with the
78
+ # right visibility.
79
+ send(visibility)
80
+
81
+ if method
82
+ define_method(name, method)
83
+ else
84
+ define_method(name, &block)
85
+ end
86
+
87
+ if block && block.arity < 0 && respond_to?(:ruby2_keywords, true)
88
+ ruby2_keywords(name)
89
+ end
90
+ end
91
+ end
92
+
72
93
  # Replaces a method, either by overwriting it (if it is defined directly on `mod`) or by
73
94
  # overriding it (if it is defined by one of mod's ancestors). Returns a ReplacedMethod instance
74
95
  # on which you can call `bind(...).call(...)` to call the original method, or `restore` to
@@ -96,13 +117,9 @@ module T::Private::ClassUtils
96
117
  overwritten = original_owner == mod
97
118
  T::Configuration.without_ruby_warnings do
98
119
  T::Private::DeclState.current.without_on_method_added do
99
- mod.send(:define_method, name, &blk)
100
- if blk.arity < 0 && mod.respond_to?(:ruby2_keywords, true)
101
- mod.send(:ruby2_keywords, name)
102
- end
120
+ def_with_visibility(mod, name, original_visibility, &blk)
103
121
  end
104
122
  end
105
- mod.send(original_visibility, name)
106
123
  new_method = mod.instance_method(name)
107
124
 
108
125
  ReplacedMethod.new(mod, original_method, new_method, overwritten, original_visibility)
@@ -40,9 +40,8 @@ module T::Private::Methods::CallValidation
40
40
  T::Configuration.without_ruby_warnings do
41
41
  # get all the shims out of the way and put back the original method
42
42
  T::Private::DeclState.current.without_on_method_added do
43
- mod.send(:define_method, method_sig.method_name, original_method)
43
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility, original_method)
44
44
  end
45
- mod.send(original_visibility, method_sig.method_name)
46
45
  end
47
46
  end
48
47
  # Return the newly created method (or the original one if we didn't replace it)
@@ -70,28 +69,25 @@ module T::Private::Methods::CallValidation
70
69
  T::Configuration.without_ruby_warnings do
71
70
  T::Private::DeclState.current.without_on_method_added do
72
71
  if simple_method
73
- create_validator_method_fast(mod, original_method, method_sig)
72
+ create_validator_method_fast(mod, original_method, method_sig, original_visibility)
74
73
  elsif simple_procedure
75
- create_validator_procedure_fast(mod, original_method, method_sig)
74
+ create_validator_procedure_fast(mod, original_method, method_sig, original_visibility)
76
75
  elsif ok_for_fast_path && method_sig.return_type.is_a?(T::Private::Types::Void)
77
- create_validator_procedure_medium(mod, original_method, method_sig)
76
+ create_validator_procedure_medium(mod, original_method, method_sig, original_visibility)
78
77
  elsif ok_for_fast_path
79
- create_validator_method_medium(mod, original_method, method_sig)
78
+ create_validator_method_medium(mod, original_method, method_sig, original_visibility)
80
79
  else
81
- create_validator_slow(mod, original_method, method_sig)
80
+ create_validator_slow(mod, original_method, method_sig, original_visibility)
82
81
  end
83
82
  end
83
+ mod.send(original_visibility, method_sig.method_name)
84
84
  end
85
- mod.send(original_visibility, method_sig.method_name)
86
85
  end
87
86
 
88
- def self.create_validator_slow(mod, original_method, method_sig)
89
- mod.send(:define_method, method_sig.method_name) do |*args, &blk|
87
+ def self.create_validator_slow(mod, original_method, method_sig, original_visibility)
88
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
90
89
  CallValidation.validate_call(self, original_method, method_sig, args, blk)
91
90
  end
92
- if mod.respond_to?(:ruby2_keywords, true)
93
- mod.send(:ruby2_keywords, method_sig.method_name)
94
- end
95
91
  end
96
92
 
97
93
  def self.validate_call(instance, original_method, method_sig, args, blk)
@@ -6,27 +6,27 @@
6
6
  # bazel test //gems/sorbet-runtime:update_call_validation
7
7
 
8
8
  module T::Private::Methods::CallValidation
9
- def self.create_validator_method_fast(mod, original_method, method_sig)
9
+ def self.create_validator_method_fast(mod, original_method, method_sig, original_visibility)
10
10
  if method_sig.return_type.is_a?(T::Private::Types::Void)
11
11
  raise 'Should have used create_validator_procedure_fast'
12
12
  end
13
13
  # trampoline to reduce stack frame size
14
14
  if method_sig.arg_types.empty?
15
- create_validator_method_fast0(mod, original_method, method_sig, method_sig.return_type.raw_type)
15
+ create_validator_method_fast0(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type)
16
16
  elsif method_sig.arg_types.length == 1
17
- create_validator_method_fast1(mod, original_method, method_sig, method_sig.return_type.raw_type,
17
+ create_validator_method_fast1(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
18
18
  method_sig.arg_types[0][1].raw_type)
19
19
  elsif method_sig.arg_types.length == 2
20
- create_validator_method_fast2(mod, original_method, method_sig, method_sig.return_type.raw_type,
20
+ create_validator_method_fast2(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
21
21
  method_sig.arg_types[0][1].raw_type,
22
22
  method_sig.arg_types[1][1].raw_type)
23
23
  elsif method_sig.arg_types.length == 3
24
- create_validator_method_fast3(mod, original_method, method_sig, method_sig.return_type.raw_type,
24
+ create_validator_method_fast3(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
25
25
  method_sig.arg_types[0][1].raw_type,
26
26
  method_sig.arg_types[1][1].raw_type,
27
27
  method_sig.arg_types[2][1].raw_type)
28
28
  elsif method_sig.arg_types.length == 4
29
- create_validator_method_fast4(mod, original_method, method_sig, method_sig.return_type.raw_type,
29
+ create_validator_method_fast4(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
30
30
  method_sig.arg_types[0][1].raw_type,
31
31
  method_sig.arg_types[1][1].raw_type,
32
32
  method_sig.arg_types[2][1].raw_type,
@@ -36,8 +36,8 @@ module T::Private::Methods::CallValidation
36
36
  end
37
37
  end
38
38
 
39
- def self.create_validator_method_fast0(mod, original_method, method_sig, return_type)
40
- mod.send(:define_method, method_sig.method_name) do |&blk|
39
+ def self.create_validator_method_fast0(mod, original_method, method_sig, original_visibility, return_type)
40
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
41
41
  # This method is a manually sped-up version of more general code in `validate_call`
42
42
  # The following line breaks are intentional to show nice pry message
43
43
 
@@ -73,8 +73,8 @@ module T::Private::Methods::CallValidation
73
73
  end
74
74
  end
75
75
 
76
- def self.create_validator_method_fast1(mod, original_method, method_sig, return_type, arg0_type)
77
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
76
+ def self.create_validator_method_fast1(mod, original_method, method_sig, original_visibility, return_type, arg0_type)
77
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
78
78
  # This method is a manually sped-up version of more general code in `validate_call`
79
79
  unless arg0.is_a?(arg0_type)
80
80
  CallValidation.report_error(
@@ -122,8 +122,8 @@ module T::Private::Methods::CallValidation
122
122
  end
123
123
  end
124
124
 
125
- def self.create_validator_method_fast2(mod, original_method, method_sig, return_type, arg0_type, arg1_type)
126
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
125
+ def self.create_validator_method_fast2(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type)
126
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
127
127
  # This method is a manually sped-up version of more general code in `validate_call`
128
128
  unless arg0.is_a?(arg0_type)
129
129
  CallValidation.report_error(
@@ -183,8 +183,8 @@ module T::Private::Methods::CallValidation
183
183
  end
184
184
  end
185
185
 
186
- def self.create_validator_method_fast3(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type)
187
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
186
+ def self.create_validator_method_fast3(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type)
187
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
188
188
  # This method is a manually sped-up version of more general code in `validate_call`
189
189
  unless arg0.is_a?(arg0_type)
190
190
  CallValidation.report_error(
@@ -256,8 +256,8 @@ module T::Private::Methods::CallValidation
256
256
  end
257
257
  end
258
258
 
259
- def self.create_validator_method_fast4(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
260
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
259
+ def self.create_validator_method_fast4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
260
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
261
261
  # This method is a manually sped-up version of more general code in `validate_call`
262
262
  unless arg0.is_a?(arg0_type)
263
263
  CallValidation.report_error(
@@ -341,24 +341,24 @@ module T::Private::Methods::CallValidation
341
341
  end
342
342
  end
343
343
 
344
- def self.create_validator_procedure_fast(mod, original_method, method_sig)
344
+ def self.create_validator_procedure_fast(mod, original_method, method_sig, original_visibility)
345
345
  # trampoline to reduce stack frame size
346
346
  if method_sig.arg_types.empty?
347
- create_validator_procedure_fast0(mod, original_method, method_sig)
347
+ create_validator_procedure_fast0(mod, original_method, method_sig, original_visibility)
348
348
  elsif method_sig.arg_types.length == 1
349
- create_validator_procedure_fast1(mod, original_method, method_sig,
349
+ create_validator_procedure_fast1(mod, original_method, method_sig, original_visibility,
350
350
  method_sig.arg_types[0][1].raw_type)
351
351
  elsif method_sig.arg_types.length == 2
352
- create_validator_procedure_fast2(mod, original_method, method_sig,
352
+ create_validator_procedure_fast2(mod, original_method, method_sig, original_visibility,
353
353
  method_sig.arg_types[0][1].raw_type,
354
354
  method_sig.arg_types[1][1].raw_type)
355
355
  elsif method_sig.arg_types.length == 3
356
- create_validator_procedure_fast3(mod, original_method, method_sig,
356
+ create_validator_procedure_fast3(mod, original_method, method_sig, original_visibility,
357
357
  method_sig.arg_types[0][1].raw_type,
358
358
  method_sig.arg_types[1][1].raw_type,
359
359
  method_sig.arg_types[2][1].raw_type)
360
360
  elsif method_sig.arg_types.length == 4
361
- create_validator_procedure_fast4(mod, original_method, method_sig,
361
+ create_validator_procedure_fast4(mod, original_method, method_sig, original_visibility,
362
362
  method_sig.arg_types[0][1].raw_type,
363
363
  method_sig.arg_types[1][1].raw_type,
364
364
  method_sig.arg_types[2][1].raw_type,
@@ -368,8 +368,8 @@ module T::Private::Methods::CallValidation
368
368
  end
369
369
  end
370
370
 
371
- def self.create_validator_procedure_fast0(mod, original_method, method_sig)
372
- mod.send(:define_method, method_sig.method_name) do |&blk|
371
+ def self.create_validator_procedure_fast0(mod, original_method, method_sig, original_visibility)
372
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
373
373
  # This method is a manually sped-up version of more general code in `validate_call`
374
374
  # The following line breaks are intentional to show nice pry message
375
375
 
@@ -391,8 +391,8 @@ module T::Private::Methods::CallValidation
391
391
  end
392
392
  end
393
393
 
394
- def self.create_validator_procedure_fast1(mod, original_method, method_sig, arg0_type)
395
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
394
+ def self.create_validator_procedure_fast1(mod, original_method, method_sig, original_visibility, arg0_type)
395
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
396
396
  # This method is a manually sped-up version of more general code in `validate_call`
397
397
  unless arg0.is_a?(arg0_type)
398
398
  CallValidation.report_error(
@@ -426,8 +426,8 @@ module T::Private::Methods::CallValidation
426
426
  end
427
427
  end
428
428
 
429
- def self.create_validator_procedure_fast2(mod, original_method, method_sig, arg0_type, arg1_type)
430
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
429
+ def self.create_validator_procedure_fast2(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type)
430
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
431
431
  # This method is a manually sped-up version of more general code in `validate_call`
432
432
  unless arg0.is_a?(arg0_type)
433
433
  CallValidation.report_error(
@@ -473,8 +473,8 @@ module T::Private::Methods::CallValidation
473
473
  end
474
474
  end
475
475
 
476
- def self.create_validator_procedure_fast3(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type)
477
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
476
+ def self.create_validator_procedure_fast3(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type)
477
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
478
478
  # This method is a manually sped-up version of more general code in `validate_call`
479
479
  unless arg0.is_a?(arg0_type)
480
480
  CallValidation.report_error(
@@ -532,8 +532,8 @@ module T::Private::Methods::CallValidation
532
532
  end
533
533
  end
534
534
 
535
- def self.create_validator_procedure_fast4(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type, arg3_type)
536
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
535
+ def self.create_validator_procedure_fast4(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type, arg3_type)
536
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
537
537
  # This method is a manually sped-up version of more general code in `validate_call`
538
538
  unless arg0.is_a?(arg0_type)
539
539
  CallValidation.report_error(
@@ -603,27 +603,27 @@ module T::Private::Methods::CallValidation
603
603
  end
604
604
  end
605
605
 
606
- def self.create_validator_method_medium(mod, original_method, method_sig)
606
+ def self.create_validator_method_medium(mod, original_method, method_sig, original_visibility)
607
607
  if method_sig.return_type.is_a?(T::Private::Types::Void)
608
608
  raise 'Should have used create_validator_procedure_medium'
609
609
  end
610
610
  # trampoline to reduce stack frame size
611
611
  if method_sig.arg_types.empty?
612
- create_validator_method_medium0(mod, original_method, method_sig, method_sig.return_type)
612
+ create_validator_method_medium0(mod, original_method, method_sig, original_visibility, method_sig.return_type)
613
613
  elsif method_sig.arg_types.length == 1
614
- create_validator_method_medium1(mod, original_method, method_sig, method_sig.return_type,
614
+ create_validator_method_medium1(mod, original_method, method_sig, original_visibility, method_sig.return_type,
615
615
  method_sig.arg_types[0][1])
616
616
  elsif method_sig.arg_types.length == 2
617
- create_validator_method_medium2(mod, original_method, method_sig, method_sig.return_type,
617
+ create_validator_method_medium2(mod, original_method, method_sig, original_visibility, method_sig.return_type,
618
618
  method_sig.arg_types[0][1],
619
619
  method_sig.arg_types[1][1])
620
620
  elsif method_sig.arg_types.length == 3
621
- create_validator_method_medium3(mod, original_method, method_sig, method_sig.return_type,
621
+ create_validator_method_medium3(mod, original_method, method_sig, original_visibility, method_sig.return_type,
622
622
  method_sig.arg_types[0][1],
623
623
  method_sig.arg_types[1][1],
624
624
  method_sig.arg_types[2][1])
625
625
  elsif method_sig.arg_types.length == 4
626
- create_validator_method_medium4(mod, original_method, method_sig, method_sig.return_type,
626
+ create_validator_method_medium4(mod, original_method, method_sig, original_visibility, method_sig.return_type,
627
627
  method_sig.arg_types[0][1],
628
628
  method_sig.arg_types[1][1],
629
629
  method_sig.arg_types[2][1],
@@ -633,8 +633,8 @@ module T::Private::Methods::CallValidation
633
633
  end
634
634
  end
635
635
 
636
- def self.create_validator_method_medium0(mod, original_method, method_sig, return_type)
637
- mod.send(:define_method, method_sig.method_name) do |&blk|
636
+ def self.create_validator_method_medium0(mod, original_method, method_sig, original_visibility, return_type)
637
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
638
638
  # This method is a manually sped-up version of more general code in `validate_call`
639
639
  # The following line breaks are intentional to show nice pry message
640
640
 
@@ -670,8 +670,8 @@ module T::Private::Methods::CallValidation
670
670
  end
671
671
  end
672
672
 
673
- def self.create_validator_method_medium1(mod, original_method, method_sig, return_type, arg0_type)
674
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
673
+ def self.create_validator_method_medium1(mod, original_method, method_sig, original_visibility, return_type, arg0_type)
674
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
675
675
  # This method is a manually sped-up version of more general code in `validate_call`
676
676
  unless arg0_type.valid?(arg0)
677
677
  CallValidation.report_error(
@@ -719,8 +719,8 @@ module T::Private::Methods::CallValidation
719
719
  end
720
720
  end
721
721
 
722
- def self.create_validator_method_medium2(mod, original_method, method_sig, return_type, arg0_type, arg1_type)
723
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
722
+ def self.create_validator_method_medium2(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type)
723
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
724
724
  # This method is a manually sped-up version of more general code in `validate_call`
725
725
  unless arg0_type.valid?(arg0)
726
726
  CallValidation.report_error(
@@ -780,8 +780,8 @@ module T::Private::Methods::CallValidation
780
780
  end
781
781
  end
782
782
 
783
- def self.create_validator_method_medium3(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type)
784
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
783
+ def self.create_validator_method_medium3(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type)
784
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
785
785
  # This method is a manually sped-up version of more general code in `validate_call`
786
786
  unless arg0_type.valid?(arg0)
787
787
  CallValidation.report_error(
@@ -853,8 +853,8 @@ module T::Private::Methods::CallValidation
853
853
  end
854
854
  end
855
855
 
856
- def self.create_validator_method_medium4(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
857
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
856
+ def self.create_validator_method_medium4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
857
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
858
858
  # This method is a manually sped-up version of more general code in `validate_call`
859
859
  unless arg0_type.valid?(arg0)
860
860
  CallValidation.report_error(
@@ -938,24 +938,24 @@ module T::Private::Methods::CallValidation
938
938
  end
939
939
  end
940
940
 
941
- def self.create_validator_procedure_medium(mod, original_method, method_sig)
941
+ def self.create_validator_procedure_medium(mod, original_method, method_sig, original_visibility)
942
942
  # trampoline to reduce stack frame size
943
943
  if method_sig.arg_types.empty?
944
- create_validator_procedure_medium0(mod, original_method, method_sig)
944
+ create_validator_procedure_medium0(mod, original_method, method_sig, original_visibility)
945
945
  elsif method_sig.arg_types.length == 1
946
- create_validator_procedure_medium1(mod, original_method, method_sig,
946
+ create_validator_procedure_medium1(mod, original_method, method_sig, original_visibility,
947
947
  method_sig.arg_types[0][1])
948
948
  elsif method_sig.arg_types.length == 2
949
- create_validator_procedure_medium2(mod, original_method, method_sig,
949
+ create_validator_procedure_medium2(mod, original_method, method_sig, original_visibility,
950
950
  method_sig.arg_types[0][1],
951
951
  method_sig.arg_types[1][1])
952
952
  elsif method_sig.arg_types.length == 3
953
- create_validator_procedure_medium3(mod, original_method, method_sig,
953
+ create_validator_procedure_medium3(mod, original_method, method_sig, original_visibility,
954
954
  method_sig.arg_types[0][1],
955
955
  method_sig.arg_types[1][1],
956
956
  method_sig.arg_types[2][1])
957
957
  elsif method_sig.arg_types.length == 4
958
- create_validator_procedure_medium4(mod, original_method, method_sig,
958
+ create_validator_procedure_medium4(mod, original_method, method_sig, original_visibility,
959
959
  method_sig.arg_types[0][1],
960
960
  method_sig.arg_types[1][1],
961
961
  method_sig.arg_types[2][1],
@@ -965,8 +965,8 @@ module T::Private::Methods::CallValidation
965
965
  end
966
966
  end
967
967
 
968
- def self.create_validator_procedure_medium0(mod, original_method, method_sig)
969
- mod.send(:define_method, method_sig.method_name) do |&blk|
968
+ def self.create_validator_procedure_medium0(mod, original_method, method_sig, original_visibility)
969
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
970
970
  # This method is a manually sped-up version of more general code in `validate_call`
971
971
  # The following line breaks are intentional to show nice pry message
972
972
 
@@ -988,8 +988,8 @@ module T::Private::Methods::CallValidation
988
988
  end
989
989
  end
990
990
 
991
- def self.create_validator_procedure_medium1(mod, original_method, method_sig, arg0_type)
992
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
991
+ def self.create_validator_procedure_medium1(mod, original_method, method_sig, original_visibility, arg0_type)
992
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
993
993
  # This method is a manually sped-up version of more general code in `validate_call`
994
994
  unless arg0_type.valid?(arg0)
995
995
  CallValidation.report_error(
@@ -1023,8 +1023,8 @@ module T::Private::Methods::CallValidation
1023
1023
  end
1024
1024
  end
1025
1025
 
1026
- def self.create_validator_procedure_medium2(mod, original_method, method_sig, arg0_type, arg1_type)
1027
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
1026
+ def self.create_validator_procedure_medium2(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type)
1027
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
1028
1028
  # This method is a manually sped-up version of more general code in `validate_call`
1029
1029
  unless arg0_type.valid?(arg0)
1030
1030
  CallValidation.report_error(
@@ -1070,8 +1070,8 @@ module T::Private::Methods::CallValidation
1070
1070
  end
1071
1071
  end
1072
1072
 
1073
- def self.create_validator_procedure_medium3(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type)
1074
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
1073
+ def self.create_validator_procedure_medium3(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type)
1074
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
1075
1075
  # This method is a manually sped-up version of more general code in `validate_call`
1076
1076
  unless arg0_type.valid?(arg0)
1077
1077
  CallValidation.report_error(
@@ -1129,8 +1129,8 @@ module T::Private::Methods::CallValidation
1129
1129
  end
1130
1130
  end
1131
1131
 
1132
- def self.create_validator_procedure_medium4(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type, arg3_type)
1133
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
1132
+ def self.create_validator_procedure_medium4(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type, arg3_type)
1133
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
1134
1134
  # This method is a manually sped-up version of more general code in `validate_call`
1135
1135
  unless arg0_type.valid?(arg0)
1136
1136
  CallValidation.report_error(
@@ -6,27 +6,27 @@
6
6
  # bazel test //gems/sorbet-runtime:update_call_validation
7
7
 
8
8
  module T::Private::Methods::CallValidation
9
- def self.create_validator_method_fast(mod, original_method, method_sig)
9
+ def self.create_validator_method_fast(mod, original_method, method_sig, original_visibility)
10
10
  if method_sig.return_type.is_a?(T::Private::Types::Void)
11
11
  raise 'Should have used create_validator_procedure_fast'
12
12
  end
13
13
  # trampoline to reduce stack frame size
14
14
  if method_sig.arg_types.empty?
15
- create_validator_method_fast0(mod, original_method, method_sig, method_sig.return_type.raw_type)
15
+ create_validator_method_fast0(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type)
16
16
  elsif method_sig.arg_types.length == 1
17
- create_validator_method_fast1(mod, original_method, method_sig, method_sig.return_type.raw_type,
17
+ create_validator_method_fast1(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
18
18
  method_sig.arg_types[0][1].raw_type)
19
19
  elsif method_sig.arg_types.length == 2
20
- create_validator_method_fast2(mod, original_method, method_sig, method_sig.return_type.raw_type,
20
+ create_validator_method_fast2(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
21
21
  method_sig.arg_types[0][1].raw_type,
22
22
  method_sig.arg_types[1][1].raw_type)
23
23
  elsif method_sig.arg_types.length == 3
24
- create_validator_method_fast3(mod, original_method, method_sig, method_sig.return_type.raw_type,
24
+ create_validator_method_fast3(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
25
25
  method_sig.arg_types[0][1].raw_type,
26
26
  method_sig.arg_types[1][1].raw_type,
27
27
  method_sig.arg_types[2][1].raw_type)
28
28
  elsif method_sig.arg_types.length == 4
29
- create_validator_method_fast4(mod, original_method, method_sig, method_sig.return_type.raw_type,
29
+ create_validator_method_fast4(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
30
30
  method_sig.arg_types[0][1].raw_type,
31
31
  method_sig.arg_types[1][1].raw_type,
32
32
  method_sig.arg_types[2][1].raw_type,
@@ -36,8 +36,8 @@ module T::Private::Methods::CallValidation
36
36
  end
37
37
  end
38
38
 
39
- def self.create_validator_method_fast0(mod, original_method, method_sig, return_type)
40
- mod.send(:define_method, method_sig.method_name) do |&blk|
39
+ def self.create_validator_method_fast0(mod, original_method, method_sig, original_visibility, return_type)
40
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
41
41
  # This method is a manually sped-up version of more general code in `validate_call`
42
42
  # The following line breaks are intentional to show nice pry message
43
43
 
@@ -73,8 +73,8 @@ module T::Private::Methods::CallValidation
73
73
  end
74
74
  end
75
75
 
76
- def self.create_validator_method_fast1(mod, original_method, method_sig, return_type, arg0_type)
77
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
76
+ def self.create_validator_method_fast1(mod, original_method, method_sig, original_visibility, return_type, arg0_type)
77
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
78
78
  # This method is a manually sped-up version of more general code in `validate_call`
79
79
  unless arg0.is_a?(arg0_type)
80
80
  CallValidation.report_error(
@@ -122,8 +122,8 @@ module T::Private::Methods::CallValidation
122
122
  end
123
123
  end
124
124
 
125
- def self.create_validator_method_fast2(mod, original_method, method_sig, return_type, arg0_type, arg1_type)
126
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
125
+ def self.create_validator_method_fast2(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type)
126
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
127
127
  # This method is a manually sped-up version of more general code in `validate_call`
128
128
  unless arg0.is_a?(arg0_type)
129
129
  CallValidation.report_error(
@@ -183,8 +183,8 @@ module T::Private::Methods::CallValidation
183
183
  end
184
184
  end
185
185
 
186
- def self.create_validator_method_fast3(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type)
187
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
186
+ def self.create_validator_method_fast3(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type)
187
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
188
188
  # This method is a manually sped-up version of more general code in `validate_call`
189
189
  unless arg0.is_a?(arg0_type)
190
190
  CallValidation.report_error(
@@ -256,8 +256,8 @@ module T::Private::Methods::CallValidation
256
256
  end
257
257
  end
258
258
 
259
- def self.create_validator_method_fast4(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
260
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
259
+ def self.create_validator_method_fast4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
260
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
261
261
  # This method is a manually sped-up version of more general code in `validate_call`
262
262
  unless arg0.is_a?(arg0_type)
263
263
  CallValidation.report_error(
@@ -341,24 +341,24 @@ module T::Private::Methods::CallValidation
341
341
  end
342
342
  end
343
343
 
344
- def self.create_validator_procedure_fast(mod, original_method, method_sig)
344
+ def self.create_validator_procedure_fast(mod, original_method, method_sig, original_visibility)
345
345
  # trampoline to reduce stack frame size
346
346
  if method_sig.arg_types.empty?
347
- create_validator_procedure_fast0(mod, original_method, method_sig)
347
+ create_validator_procedure_fast0(mod, original_method, method_sig, original_visibility)
348
348
  elsif method_sig.arg_types.length == 1
349
- create_validator_procedure_fast1(mod, original_method, method_sig,
349
+ create_validator_procedure_fast1(mod, original_method, method_sig, original_visibility,
350
350
  method_sig.arg_types[0][1].raw_type)
351
351
  elsif method_sig.arg_types.length == 2
352
- create_validator_procedure_fast2(mod, original_method, method_sig,
352
+ create_validator_procedure_fast2(mod, original_method, method_sig, original_visibility,
353
353
  method_sig.arg_types[0][1].raw_type,
354
354
  method_sig.arg_types[1][1].raw_type)
355
355
  elsif method_sig.arg_types.length == 3
356
- create_validator_procedure_fast3(mod, original_method, method_sig,
356
+ create_validator_procedure_fast3(mod, original_method, method_sig, original_visibility,
357
357
  method_sig.arg_types[0][1].raw_type,
358
358
  method_sig.arg_types[1][1].raw_type,
359
359
  method_sig.arg_types[2][1].raw_type)
360
360
  elsif method_sig.arg_types.length == 4
361
- create_validator_procedure_fast4(mod, original_method, method_sig,
361
+ create_validator_procedure_fast4(mod, original_method, method_sig, original_visibility,
362
362
  method_sig.arg_types[0][1].raw_type,
363
363
  method_sig.arg_types[1][1].raw_type,
364
364
  method_sig.arg_types[2][1].raw_type,
@@ -368,8 +368,8 @@ module T::Private::Methods::CallValidation
368
368
  end
369
369
  end
370
370
 
371
- def self.create_validator_procedure_fast0(mod, original_method, method_sig)
372
- mod.send(:define_method, method_sig.method_name) do |&blk|
371
+ def self.create_validator_procedure_fast0(mod, original_method, method_sig, original_visibility)
372
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
373
373
  # This method is a manually sped-up version of more general code in `validate_call`
374
374
  # The following line breaks are intentional to show nice pry message
375
375
 
@@ -391,8 +391,8 @@ module T::Private::Methods::CallValidation
391
391
  end
392
392
  end
393
393
 
394
- def self.create_validator_procedure_fast1(mod, original_method, method_sig, arg0_type)
395
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
394
+ def self.create_validator_procedure_fast1(mod, original_method, method_sig, original_visibility, arg0_type)
395
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
396
396
  # This method is a manually sped-up version of more general code in `validate_call`
397
397
  unless arg0.is_a?(arg0_type)
398
398
  CallValidation.report_error(
@@ -426,8 +426,8 @@ module T::Private::Methods::CallValidation
426
426
  end
427
427
  end
428
428
 
429
- def self.create_validator_procedure_fast2(mod, original_method, method_sig, arg0_type, arg1_type)
430
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
429
+ def self.create_validator_procedure_fast2(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type)
430
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
431
431
  # This method is a manually sped-up version of more general code in `validate_call`
432
432
  unless arg0.is_a?(arg0_type)
433
433
  CallValidation.report_error(
@@ -473,8 +473,8 @@ module T::Private::Methods::CallValidation
473
473
  end
474
474
  end
475
475
 
476
- def self.create_validator_procedure_fast3(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type)
477
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
476
+ def self.create_validator_procedure_fast3(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type)
477
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
478
478
  # This method is a manually sped-up version of more general code in `validate_call`
479
479
  unless arg0.is_a?(arg0_type)
480
480
  CallValidation.report_error(
@@ -532,8 +532,8 @@ module T::Private::Methods::CallValidation
532
532
  end
533
533
  end
534
534
 
535
- def self.create_validator_procedure_fast4(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type, arg3_type)
536
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
535
+ def self.create_validator_procedure_fast4(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type, arg3_type)
536
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
537
537
  # This method is a manually sped-up version of more general code in `validate_call`
538
538
  unless arg0.is_a?(arg0_type)
539
539
  CallValidation.report_error(
@@ -603,27 +603,27 @@ module T::Private::Methods::CallValidation
603
603
  end
604
604
  end
605
605
 
606
- def self.create_validator_method_medium(mod, original_method, method_sig)
606
+ def self.create_validator_method_medium(mod, original_method, method_sig, original_visibility)
607
607
  if method_sig.return_type.is_a?(T::Private::Types::Void)
608
608
  raise 'Should have used create_validator_procedure_medium'
609
609
  end
610
610
  # trampoline to reduce stack frame size
611
611
  if method_sig.arg_types.empty?
612
- create_validator_method_medium0(mod, original_method, method_sig, method_sig.return_type)
612
+ create_validator_method_medium0(mod, original_method, method_sig, original_visibility, method_sig.return_type)
613
613
  elsif method_sig.arg_types.length == 1
614
- create_validator_method_medium1(mod, original_method, method_sig, method_sig.return_type,
614
+ create_validator_method_medium1(mod, original_method, method_sig, original_visibility, method_sig.return_type,
615
615
  method_sig.arg_types[0][1])
616
616
  elsif method_sig.arg_types.length == 2
617
- create_validator_method_medium2(mod, original_method, method_sig, method_sig.return_type,
617
+ create_validator_method_medium2(mod, original_method, method_sig, original_visibility, method_sig.return_type,
618
618
  method_sig.arg_types[0][1],
619
619
  method_sig.arg_types[1][1])
620
620
  elsif method_sig.arg_types.length == 3
621
- create_validator_method_medium3(mod, original_method, method_sig, method_sig.return_type,
621
+ create_validator_method_medium3(mod, original_method, method_sig, original_visibility, method_sig.return_type,
622
622
  method_sig.arg_types[0][1],
623
623
  method_sig.arg_types[1][1],
624
624
  method_sig.arg_types[2][1])
625
625
  elsif method_sig.arg_types.length == 4
626
- create_validator_method_medium4(mod, original_method, method_sig, method_sig.return_type,
626
+ create_validator_method_medium4(mod, original_method, method_sig, original_visibility, method_sig.return_type,
627
627
  method_sig.arg_types[0][1],
628
628
  method_sig.arg_types[1][1],
629
629
  method_sig.arg_types[2][1],
@@ -633,8 +633,8 @@ module T::Private::Methods::CallValidation
633
633
  end
634
634
  end
635
635
 
636
- def self.create_validator_method_medium0(mod, original_method, method_sig, return_type)
637
- mod.send(:define_method, method_sig.method_name) do |&blk|
636
+ def self.create_validator_method_medium0(mod, original_method, method_sig, original_visibility, return_type)
637
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
638
638
  # This method is a manually sped-up version of more general code in `validate_call`
639
639
  # The following line breaks are intentional to show nice pry message
640
640
 
@@ -670,8 +670,8 @@ module T::Private::Methods::CallValidation
670
670
  end
671
671
  end
672
672
 
673
- def self.create_validator_method_medium1(mod, original_method, method_sig, return_type, arg0_type)
674
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
673
+ def self.create_validator_method_medium1(mod, original_method, method_sig, original_visibility, return_type, arg0_type)
674
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
675
675
  # This method is a manually sped-up version of more general code in `validate_call`
676
676
  unless arg0_type.valid?(arg0)
677
677
  CallValidation.report_error(
@@ -719,8 +719,8 @@ module T::Private::Methods::CallValidation
719
719
  end
720
720
  end
721
721
 
722
- def self.create_validator_method_medium2(mod, original_method, method_sig, return_type, arg0_type, arg1_type)
723
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
722
+ def self.create_validator_method_medium2(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type)
723
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
724
724
  # This method is a manually sped-up version of more general code in `validate_call`
725
725
  unless arg0_type.valid?(arg0)
726
726
  CallValidation.report_error(
@@ -780,8 +780,8 @@ module T::Private::Methods::CallValidation
780
780
  end
781
781
  end
782
782
 
783
- def self.create_validator_method_medium3(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type)
784
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
783
+ def self.create_validator_method_medium3(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type)
784
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
785
785
  # This method is a manually sped-up version of more general code in `validate_call`
786
786
  unless arg0_type.valid?(arg0)
787
787
  CallValidation.report_error(
@@ -853,8 +853,8 @@ module T::Private::Methods::CallValidation
853
853
  end
854
854
  end
855
855
 
856
- def self.create_validator_method_medium4(mod, original_method, method_sig, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
857
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
856
+ def self.create_validator_method_medium4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
857
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
858
858
  # This method is a manually sped-up version of more general code in `validate_call`
859
859
  unless arg0_type.valid?(arg0)
860
860
  CallValidation.report_error(
@@ -938,24 +938,24 @@ module T::Private::Methods::CallValidation
938
938
  end
939
939
  end
940
940
 
941
- def self.create_validator_procedure_medium(mod, original_method, method_sig)
941
+ def self.create_validator_procedure_medium(mod, original_method, method_sig, original_visibility)
942
942
  # trampoline to reduce stack frame size
943
943
  if method_sig.arg_types.empty?
944
- create_validator_procedure_medium0(mod, original_method, method_sig)
944
+ create_validator_procedure_medium0(mod, original_method, method_sig, original_visibility)
945
945
  elsif method_sig.arg_types.length == 1
946
- create_validator_procedure_medium1(mod, original_method, method_sig,
946
+ create_validator_procedure_medium1(mod, original_method, method_sig, original_visibility,
947
947
  method_sig.arg_types[0][1])
948
948
  elsif method_sig.arg_types.length == 2
949
- create_validator_procedure_medium2(mod, original_method, method_sig,
949
+ create_validator_procedure_medium2(mod, original_method, method_sig, original_visibility,
950
950
  method_sig.arg_types[0][1],
951
951
  method_sig.arg_types[1][1])
952
952
  elsif method_sig.arg_types.length == 3
953
- create_validator_procedure_medium3(mod, original_method, method_sig,
953
+ create_validator_procedure_medium3(mod, original_method, method_sig, original_visibility,
954
954
  method_sig.arg_types[0][1],
955
955
  method_sig.arg_types[1][1],
956
956
  method_sig.arg_types[2][1])
957
957
  elsif method_sig.arg_types.length == 4
958
- create_validator_procedure_medium4(mod, original_method, method_sig,
958
+ create_validator_procedure_medium4(mod, original_method, method_sig, original_visibility,
959
959
  method_sig.arg_types[0][1],
960
960
  method_sig.arg_types[1][1],
961
961
  method_sig.arg_types[2][1],
@@ -965,8 +965,8 @@ module T::Private::Methods::CallValidation
965
965
  end
966
966
  end
967
967
 
968
- def self.create_validator_procedure_medium0(mod, original_method, method_sig)
969
- mod.send(:define_method, method_sig.method_name) do |&blk|
968
+ def self.create_validator_procedure_medium0(mod, original_method, method_sig, original_visibility)
969
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
970
970
  # This method is a manually sped-up version of more general code in `validate_call`
971
971
  # The following line breaks are intentional to show nice pry message
972
972
 
@@ -988,8 +988,8 @@ module T::Private::Methods::CallValidation
988
988
  end
989
989
  end
990
990
 
991
- def self.create_validator_procedure_medium1(mod, original_method, method_sig, arg0_type)
992
- mod.send(:define_method, method_sig.method_name) do |arg0, &blk|
991
+ def self.create_validator_procedure_medium1(mod, original_method, method_sig, original_visibility, arg0_type)
992
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
993
993
  # This method is a manually sped-up version of more general code in `validate_call`
994
994
  unless arg0_type.valid?(arg0)
995
995
  CallValidation.report_error(
@@ -1023,8 +1023,8 @@ module T::Private::Methods::CallValidation
1023
1023
  end
1024
1024
  end
1025
1025
 
1026
- def self.create_validator_procedure_medium2(mod, original_method, method_sig, arg0_type, arg1_type)
1027
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, &blk|
1026
+ def self.create_validator_procedure_medium2(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type)
1027
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
1028
1028
  # This method is a manually sped-up version of more general code in `validate_call`
1029
1029
  unless arg0_type.valid?(arg0)
1030
1030
  CallValidation.report_error(
@@ -1070,8 +1070,8 @@ module T::Private::Methods::CallValidation
1070
1070
  end
1071
1071
  end
1072
1072
 
1073
- def self.create_validator_procedure_medium3(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type)
1074
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, &blk|
1073
+ def self.create_validator_procedure_medium3(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type)
1074
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
1075
1075
  # This method is a manually sped-up version of more general code in `validate_call`
1076
1076
  unless arg0_type.valid?(arg0)
1077
1077
  CallValidation.report_error(
@@ -1129,8 +1129,8 @@ module T::Private::Methods::CallValidation
1129
1129
  end
1130
1130
  end
1131
1131
 
1132
- def self.create_validator_procedure_medium4(mod, original_method, method_sig, arg0_type, arg1_type, arg2_type, arg3_type)
1133
- mod.send(:define_method, method_sig.method_name) do |arg0, arg1, arg2, arg3, &blk|
1132
+ def self.create_validator_procedure_medium4(mod, original_method, method_sig, original_visibility, arg0_type, arg1_type, arg2_type, arg3_type)
1133
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
1134
1134
  # This method is a manually sped-up version of more general code in `validate_call`
1135
1135
  unless arg0_type.valid?(arg0)
1136
1136
  CallValidation.report_error(
@@ -58,6 +58,14 @@ class T::Props::Decorator
58
58
  @props = @props.merge(prop => rules.freeze).freeze
59
59
  end
60
60
 
61
+ # Heads up!
62
+ #
63
+ # There are already too many ad-hoc options on the prop DSL.
64
+ #
65
+ # We have already done a lot of work to remove unnecessary and confusing
66
+ # options. If you're considering adding a new rule key, please come chat with
67
+ # the Sorbet team first, as we'd really like to learn more about how to best
68
+ # solve the problem you're encountering.
61
69
  VALID_RULE_KEYS = T.let(%i[
62
70
  enum
63
71
  foreign
@@ -12,6 +12,14 @@ end
12
12
  module T::Props::Optional::DecoratorMethods
13
13
  extend T::Sig
14
14
 
15
+ # Heads up!
16
+ #
17
+ # There are already too many ad-hoc options on the prop DSL.
18
+ #
19
+ # We have already done a lot of work to remove unnecessary and confusing
20
+ # options. If you're considering adding a new rule key, please come chat with
21
+ # the Sorbet team first, as we'd really like to learn more about how to best
22
+ # solve the problem you're encountering.
15
23
  VALID_RULE_KEYS = {
16
24
  default: true,
17
25
  factory: true,
@@ -179,6 +179,14 @@ end
179
179
  module T::Props::Serializable::DecoratorMethods
180
180
  include T::Props::HasLazilySpecializedMethods::DecoratorMethods
181
181
 
182
+ # Heads up!
183
+ #
184
+ # There are already too many ad-hoc options on the prop DSL.
185
+ #
186
+ # We have already done a lot of work to remove unnecessary and confusing
187
+ # options. If you're considering adding a new rule key, please come chat with
188
+ # the Sorbet team first, as we'd really like to learn more about how to best
189
+ # solve the problem you're encountering.
182
190
  VALID_RULE_KEYS = {dont_store: true, name: true, raise_on_nil_write: true}.freeze
183
191
  private_constant :VALID_RULE_KEYS
184
192
 
data/lib/types/struct.rb CHANGED
@@ -16,3 +16,36 @@ class T::Struct < T::InexactStruct
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ class T::ImmutableStruct < T::InexactStruct
21
+ extend T::Sig
22
+
23
+ def self.inherited(subclass)
24
+ super(subclass)
25
+
26
+ T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited) do |s|
27
+ super(s)
28
+ raise "#{self.name} is a subclass of T::ImmutableStruct and cannot be subclassed"
29
+ end
30
+ end
31
+
32
+ # Matches the one in WeakConstructor, but freezes the object
33
+ sig {params(hash: T::Hash[Symbol, T.untyped]).void.checked(:never)}
34
+ def initialize(hash={})
35
+ super
36
+
37
+ freeze
38
+ end
39
+
40
+ # Matches the signature in Props, but raises since this is an immutable struct and only const is allowed
41
+ sig {params(name: Symbol, cls: T.untyped, rules: T.untyped).void}
42
+ def self.prop(name, cls, rules={})
43
+ return super if (cls.is_a?(Hash) && cls[:immutable]) || rules[:immutable]
44
+
45
+ raise "Cannot use `prop` in #{self.name} because it is an immutable struct. Use `const` instead"
46
+ end
47
+
48
+ def with(changed_props)
49
+ raise "Cannot use `with` in #{self.class.name} because it is an immutable struct"
50
+ end
51
+ end
@@ -10,7 +10,10 @@ module T::Types
10
10
  VALID_VARIANCES = %i[in out invariant].freeze
11
11
 
12
12
  def initialize(variance)
13
- if !VALID_VARIANCES.include?(variance)
13
+ case variance
14
+ when Hash then raise ArgumentError.new("Pass bounds using a block. Got: #{variance}")
15
+ when *VALID_VARIANCES then nil
16
+ else
14
17
  raise TypeError.new("invalid variance #{variance}")
15
18
  end
16
19
  @variance = variance
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.9889
4
+ version: 0.5.10400
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-14 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest