sorbet-runtime 0.5.10782 → 0.5.10993

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 775572c19008cfccf4857dea03c7a20af6425eeb6e9c252d7411b6d07b102bd7
4
- data.tar.gz: 4372ece549f9e340865242ad15e0b3d1bb4ecf5e1532f1867bc7d315a4ae95ca
3
+ metadata.gz: a0f91e65ae1b0e498c5df805b8f45638368257bba5b57c83153d73468c93c902
4
+ data.tar.gz: c183a3eb926674965fb519fe6fd03450151134fd14e494d3cf9cbdb2214fefb3
5
5
  SHA512:
6
- metadata.gz: df20b3fbeb6e4d7c2abafcb49d029d35acc6c4c3c4a94768b32653d9c5377726db173c7f93719549c4271baddf74d7736ab2d90c4543cb0116cd59a355f7535b
7
- data.tar.gz: 15d21f62ed38ce9cd1c132b63e4639ab19aed9c29abe2bfbb79fbdbf10d0372abdc8595b748110fe33f7cdf83b65cdaa034e64a55e9267d2e46fed53e790fda1
6
+ metadata.gz: a4e0e8d924176d843836921e5b8de7b768ec85636aaba35d05e8329225bf92854e979a8c6e8ee373de5568c2fc1f57f3a1b069197c0b6849942561f7cd16e395
7
+ data.tar.gz: c75f0f7590bc1b1e481f674e537497b69969bebeaa8866cea12994e63b62d3366dad7fbc583cdfff7c67392e76294374ef16e1946234ecc9be1ae4429211152b
@@ -85,6 +85,7 @@ require_relative 'types/boolean'
85
85
 
86
86
  # Depends on types/utils
87
87
  require_relative 'types/types/typed_array'
88
+ require_relative 'types/types/typed_class'
88
89
 
89
90
  # Props dependencies
90
91
  require_relative 'types/private/abstract/data'
data/lib/types/_types.rb CHANGED
@@ -123,7 +123,7 @@ module T
123
123
  # .returns(T::Array[T.type_parameter(:U)])
124
124
  # def map(&blk); end
125
125
  def self.type_parameter(name)
126
- T::Types::TypeParameter.new(name)
126
+ T::Types::TypeParameter.make(name)
127
127
  end
128
128
 
129
129
  # Tells the typechecker that `value` is of type `type`. Use this to get additional checking after
@@ -355,4 +355,16 @@ module T
355
355
  end
356
356
  end
357
357
  end
358
+
359
+ module Class
360
+ def self.[](type)
361
+ if type.is_a?(T::Types::Untyped)
362
+ T::Types::TypedClass::Untyped::Private::INSTANCE
363
+ elsif type.is_a?(T::Types::Anything)
364
+ T::Types::TypedClass::Anything::Private::INSTANCE
365
+ else
366
+ T::Types::TypedClass::Private::Pool.type_for_module(type)
367
+ end
368
+ end
369
+ end
358
370
  end
data/lib/types/enum.rb CHANGED
@@ -357,7 +357,7 @@ class T::Enum
357
357
  @fully_initialized = true
358
358
  end
359
359
 
360
- sig {params(child_class: Module).void}
360
+ sig {params(child_class: T::Class[T.anything]).void}
361
361
  def self.inherited(child_class)
362
362
  super
363
363
 
@@ -27,26 +27,27 @@ module T::Private::Abstract::Declare
27
27
  raise "Classes can't be interfaces. Use `abstract!` instead of `interface!`."
28
28
  end
29
29
 
30
- if mod.instance_method(:initialize).owner == mod
31
- raise "You must call `abstract!` *before* defining an initialize method"
30
+ if Object.instance_method(:method).bind_call(mod, :new).owner == mod
31
+ raise "You must call `abstract!` *before* defining a `new` method"
32
32
  end
33
33
 
34
34
  # Don't need to silence warnings via without_ruby_warnings when calling
35
35
  # define_method because of the guard above
36
36
 
37
- mod.send(:define_method, :initialize) do |*args, &blk|
38
- if self.class == mod
39
- raise "#{mod} is declared as abstract; it cannot be instantiated"
37
+ mod.send(:define_singleton_method, :new) do |*args, &blk|
38
+ super(*args, &blk).tap do |result|
39
+ if result.instance_of?(mod)
40
+ raise "#{mod} is declared as abstract; it cannot be instantiated"
41
+ end
40
42
  end
41
- super(*args, &blk)
42
43
  end
43
44
 
44
45
  # Ruby doesn not emit "method redefined" warnings for aliased methods
45
46
  # (more robust than undef_method that would create a small window in which the method doesn't exist)
46
- mod.send(:alias_method, :initialize, :initialize)
47
+ mod.singleton_class.send(:alias_method, :new, :new)
47
48
 
48
- if mod.respond_to?(:ruby2_keywords, true)
49
- mod.send(:ruby2_keywords, :initialize)
49
+ if mod.singleton_class.respond_to?(:ruby2_keywords, true)
50
+ mod.singleton_class.send(:ruby2_keywords, :new)
50
51
  end
51
52
  end
52
53
  end
@@ -91,10 +91,13 @@ module T::Private::ClassUtils
91
91
  end
92
92
 
93
93
  # Replaces a method, either by overwriting it (if it is defined directly on `mod`) or by
94
- # overriding it (if it is defined by one of mod's ancestors). Returns a ReplacedMethod instance
95
- # on which you can call `bind(...).call(...)` to call the original method, or `restore` to
96
- # restore the original method (by overwriting or removing the override).
97
- def self.replace_method(mod, name, &blk)
94
+ # overriding it (if it is defined by one of mod's ancestors). If `original_only` is
95
+ # false, returns a ReplacedMethod instance on which you can call `bind(...).call(...)`
96
+ # to call the original method, or `restore` to restore the original method (by
97
+ # overwriting or removing the override).
98
+ #
99
+ # If `original_only` is true, return the `UnboundMethod` representing the original method.
100
+ def self.replace_method(mod, name, original_only=false, &blk)
98
101
  original_method = mod.instance_method(name)
99
102
  original_visibility = visibility_method_name(mod, name)
100
103
  original_owner = original_method.owner
@@ -120,8 +123,12 @@ module T::Private::ClassUtils
120
123
  def_with_visibility(mod, name, original_visibility, &blk)
121
124
  end
122
125
  end
123
- new_method = mod.instance_method(name)
124
126
 
125
- ReplacedMethod.new(mod, original_method, new_method, overwritten, original_visibility)
127
+ if original_only
128
+ original_method
129
+ else
130
+ new_method = mod.instance_method(name)
131
+ ReplacedMethod.new(mod, original_method, new_method, overwritten, original_visibility)
132
+ end
126
133
  end
127
134
  end
@@ -163,7 +163,7 @@ module T::Private::Methods
163
163
 
164
164
  definition_file, definition_line = T::Private::Methods.signature_for_method(ancestor.instance_method(method_name)).method.source_location
165
165
  is_redefined = target == ancestor
166
- caller_loc = caller_locations&.find {|l| !l.to_s.start_with?(SORBET_RUNTIME_LIB_PATH)}
166
+ caller_loc = caller_locations.find {|l| !l.to_s.start_with?(SORBET_RUNTIME_LIB_PATH)}
167
167
  extra_info = "\n"
168
168
  if caller_loc
169
169
  extra_info = (is_redefined ? "Redefined" : "Overridden") + " here: #{caller_loc.path}:#{caller_loc.lineno}\n"
@@ -252,7 +252,7 @@ module T::Private::Methods
252
252
  # (or unwrap back to the original method).
253
253
  key = method_owner_and_name_to_key(mod, method_name)
254
254
  unless current_declaration.raw
255
- T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
255
+ T::Private::ClassUtils.replace_method(mod, method_name, true) do |*args, &blk|
256
256
  method_sig = T::Private::Methods.maybe_run_sig_block_for_key(key)
257
257
  method_sig ||= T::Private::Methods._handle_missing_method_signature(
258
258
  self,
@@ -501,19 +501,37 @@ module T::Private::Methods
501
501
  return
502
502
  end
503
503
  if is_enabled
504
- @old_hooks.each(&:restore)
504
+ # A cut-down version of T::Private::ClassUtils::ReplacedMethod#restore, because we
505
+ # should only be resetting final hooks during tests.
506
+ T::Configuration.without_ruby_warnings do
507
+ Module.define_method(:included, @old_hooks[0])
508
+ Module.define_method(:extended, @old_hooks[1])
509
+ Class.define_method(:inherited, @old_hooks[2])
510
+ end
505
511
  @old_hooks = nil
506
512
  else
507
- old_included = T::Private::ClassUtils.replace_method(Module, :included) do |arg|
508
- old_included.bind(self).call(arg)
513
+ old_included = T::Private::ClassUtils.replace_method(Module, :included, true) do |arg|
514
+ if T::Configuration::AT_LEAST_RUBY_2_7
515
+ old_included.bind_call(self, arg)
516
+ else
517
+ old_included.bind(self).call(arg)
518
+ end
509
519
  ::T::Private::Methods._hook_impl(arg, false, self)
510
520
  end
511
- old_extended = T::Private::ClassUtils.replace_method(Module, :extended) do |arg|
512
- old_extended.bind(self).call(arg)
521
+ old_extended = T::Private::ClassUtils.replace_method(Module, :extended, true) do |arg|
522
+ if T::Configuration::AT_LEAST_RUBY_2_7
523
+ old_extended.bind_call(self, arg)
524
+ else
525
+ old_extended.bind(self).call(arg)
526
+ end
513
527
  ::T::Private::Methods._hook_impl(arg, true, self)
514
528
  end
515
- old_inherited = T::Private::ClassUtils.replace_method(Class, :inherited) do |arg|
516
- old_inherited.bind(self).call(arg)
529
+ old_inherited = T::Private::ClassUtils.replace_method(Class, :inherited, true) do |arg|
530
+ if T::Configuration::AT_LEAST_RUBY_2_7
531
+ old_inherited.bind_call(self, arg)
532
+ else
533
+ old_inherited.bind(self).call(arg)
534
+ end
517
535
  ::T::Private::Methods._hook_impl(arg, false, self)
518
536
  end
519
537
  @old_hooks = [old_included, old_extended, old_inherited]
@@ -14,7 +14,7 @@ module T::Private::Methods::CallValidation
14
14
  def self.wrap_method_if_needed(mod, method_sig, original_method)
15
15
  original_visibility = visibility_method_name(mod, method_sig.method_name)
16
16
  if method_sig.mode == T::Private::Methods::Modes.abstract
17
- T::Private::ClassUtils.replace_method(mod, method_sig.method_name) do |*args, &blk|
17
+ T::Private::ClassUtils.replace_method(mod, method_sig.method_name, true) do |*args, &blk|
18
18
  # TODO: write a cop to ensure that abstract methods have an empty body
19
19
  #
20
20
  # We allow abstract methods to be implemented by things further down the ancestor chain.
@@ -11,26 +11,28 @@ module T::Private::Methods::CallValidation
11
11
  raise 'Should have used create_validator_procedure_fast'
12
12
  end
13
13
  # trampoline to reduce stack frame size
14
- if method_sig.arg_types.empty?
14
+ arg_types = method_sig.arg_types
15
+ case arg_types.length
16
+ when 0
15
17
  create_validator_method_fast0(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type)
16
- elsif method_sig.arg_types.length == 1
18
+ when 1
17
19
  create_validator_method_fast1(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
18
- method_sig.arg_types[0][1].raw_type)
19
- elsif method_sig.arg_types.length == 2
20
+ arg_types[0][1].raw_type)
21
+ when 2
20
22
  create_validator_method_fast2(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
21
- method_sig.arg_types[0][1].raw_type,
22
- method_sig.arg_types[1][1].raw_type)
23
- elsif method_sig.arg_types.length == 3
23
+ arg_types[0][1].raw_type,
24
+ arg_types[1][1].raw_type)
25
+ when 3
24
26
  create_validator_method_fast3(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
25
- method_sig.arg_types[0][1].raw_type,
26
- method_sig.arg_types[1][1].raw_type,
27
- method_sig.arg_types[2][1].raw_type)
28
- elsif method_sig.arg_types.length == 4
27
+ arg_types[0][1].raw_type,
28
+ arg_types[1][1].raw_type,
29
+ arg_types[2][1].raw_type)
30
+ when 4
29
31
  create_validator_method_fast4(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
30
- method_sig.arg_types[0][1].raw_type,
31
- method_sig.arg_types[1][1].raw_type,
32
- method_sig.arg_types[2][1].raw_type,
33
- method_sig.arg_types[3][1].raw_type)
32
+ arg_types[0][1].raw_type,
33
+ arg_types[1][1].raw_type,
34
+ arg_types[2][1].raw_type,
35
+ arg_types[3][1].raw_type)
34
36
  else
35
37
  raise 'should not happen'
36
38
  end
@@ -343,26 +345,28 @@ module T::Private::Methods::CallValidation
343
345
 
344
346
  def self.create_validator_procedure_fast(mod, original_method, method_sig, original_visibility)
345
347
  # trampoline to reduce stack frame size
346
- if method_sig.arg_types.empty?
348
+ arg_types = method_sig.arg_types
349
+ case arg_types.length
350
+ when 0
347
351
  create_validator_procedure_fast0(mod, original_method, method_sig, original_visibility)
348
- elsif method_sig.arg_types.length == 1
352
+ when 1
349
353
  create_validator_procedure_fast1(mod, original_method, method_sig, original_visibility,
350
- method_sig.arg_types[0][1].raw_type)
351
- elsif method_sig.arg_types.length == 2
354
+ arg_types[0][1].raw_type)
355
+ when 2
352
356
  create_validator_procedure_fast2(mod, original_method, method_sig, original_visibility,
353
- method_sig.arg_types[0][1].raw_type,
354
- method_sig.arg_types[1][1].raw_type)
355
- elsif method_sig.arg_types.length == 3
357
+ arg_types[0][1].raw_type,
358
+ arg_types[1][1].raw_type)
359
+ when 3
356
360
  create_validator_procedure_fast3(mod, original_method, method_sig, original_visibility,
357
- method_sig.arg_types[0][1].raw_type,
358
- method_sig.arg_types[1][1].raw_type,
359
- method_sig.arg_types[2][1].raw_type)
360
- elsif method_sig.arg_types.length == 4
361
+ arg_types[0][1].raw_type,
362
+ arg_types[1][1].raw_type,
363
+ arg_types[2][1].raw_type)
364
+ when 4
361
365
  create_validator_procedure_fast4(mod, original_method, method_sig, original_visibility,
362
- method_sig.arg_types[0][1].raw_type,
363
- method_sig.arg_types[1][1].raw_type,
364
- method_sig.arg_types[2][1].raw_type,
365
- method_sig.arg_types[3][1].raw_type)
366
+ arg_types[0][1].raw_type,
367
+ arg_types[1][1].raw_type,
368
+ arg_types[2][1].raw_type,
369
+ arg_types[3][1].raw_type)
366
370
  else
367
371
  raise 'should not happen'
368
372
  end
@@ -608,26 +612,28 @@ module T::Private::Methods::CallValidation
608
612
  raise 'Should have used create_validator_procedure_medium'
609
613
  end
610
614
  # trampoline to reduce stack frame size
611
- if method_sig.arg_types.empty?
615
+ arg_types = method_sig.arg_types
616
+ case arg_types.length
617
+ when 0
612
618
  create_validator_method_medium0(mod, original_method, method_sig, original_visibility, method_sig.return_type)
613
- elsif method_sig.arg_types.length == 1
619
+ when 1
614
620
  create_validator_method_medium1(mod, original_method, method_sig, original_visibility, method_sig.return_type,
615
- method_sig.arg_types[0][1])
616
- elsif method_sig.arg_types.length == 2
621
+ arg_types[0][1])
622
+ when 2
617
623
  create_validator_method_medium2(mod, original_method, method_sig, original_visibility, method_sig.return_type,
618
- method_sig.arg_types[0][1],
619
- method_sig.arg_types[1][1])
620
- elsif method_sig.arg_types.length == 3
624
+ arg_types[0][1],
625
+ arg_types[1][1])
626
+ when 3
621
627
  create_validator_method_medium3(mod, original_method, method_sig, original_visibility, method_sig.return_type,
622
- method_sig.arg_types[0][1],
623
- method_sig.arg_types[1][1],
624
- method_sig.arg_types[2][1])
625
- elsif method_sig.arg_types.length == 4
628
+ arg_types[0][1],
629
+ arg_types[1][1],
630
+ arg_types[2][1])
631
+ when 4
626
632
  create_validator_method_medium4(mod, original_method, method_sig, original_visibility, method_sig.return_type,
627
- method_sig.arg_types[0][1],
628
- method_sig.arg_types[1][1],
629
- method_sig.arg_types[2][1],
630
- method_sig.arg_types[3][1])
633
+ arg_types[0][1],
634
+ arg_types[1][1],
635
+ arg_types[2][1],
636
+ arg_types[3][1])
631
637
  else
632
638
  raise 'should not happen'
633
639
  end
@@ -940,26 +946,28 @@ module T::Private::Methods::CallValidation
940
946
 
941
947
  def self.create_validator_procedure_medium(mod, original_method, method_sig, original_visibility)
942
948
  # trampoline to reduce stack frame size
943
- if method_sig.arg_types.empty?
949
+ arg_types = method_sig.arg_types
950
+ case arg_types.length
951
+ when 0
944
952
  create_validator_procedure_medium0(mod, original_method, method_sig, original_visibility)
945
- elsif method_sig.arg_types.length == 1
953
+ when 1
946
954
  create_validator_procedure_medium1(mod, original_method, method_sig, original_visibility,
947
- method_sig.arg_types[0][1])
948
- elsif method_sig.arg_types.length == 2
955
+ arg_types[0][1])
956
+ when 2
949
957
  create_validator_procedure_medium2(mod, original_method, method_sig, original_visibility,
950
- method_sig.arg_types[0][1],
951
- method_sig.arg_types[1][1])
952
- elsif method_sig.arg_types.length == 3
958
+ arg_types[0][1],
959
+ arg_types[1][1])
960
+ when 3
953
961
  create_validator_procedure_medium3(mod, original_method, method_sig, original_visibility,
954
- method_sig.arg_types[0][1],
955
- method_sig.arg_types[1][1],
956
- method_sig.arg_types[2][1])
957
- elsif method_sig.arg_types.length == 4
962
+ arg_types[0][1],
963
+ arg_types[1][1],
964
+ arg_types[2][1])
965
+ when 4
958
966
  create_validator_procedure_medium4(mod, original_method, method_sig, original_visibility,
959
- method_sig.arg_types[0][1],
960
- method_sig.arg_types[1][1],
961
- method_sig.arg_types[2][1],
962
- method_sig.arg_types[3][1])
967
+ arg_types[0][1],
968
+ arg_types[1][1],
969
+ arg_types[2][1],
970
+ arg_types[3][1])
963
971
  else
964
972
  raise 'should not happen'
965
973
  end
@@ -11,26 +11,28 @@ module T::Private::Methods::CallValidation
11
11
  raise 'Should have used create_validator_procedure_fast'
12
12
  end
13
13
  # trampoline to reduce stack frame size
14
- if method_sig.arg_types.empty?
14
+ arg_types = method_sig.arg_types
15
+ case arg_types.length
16
+ when 0
15
17
  create_validator_method_fast0(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type)
16
- elsif method_sig.arg_types.length == 1
18
+ when 1
17
19
  create_validator_method_fast1(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
18
- method_sig.arg_types[0][1].raw_type)
19
- elsif method_sig.arg_types.length == 2
20
+ arg_types[0][1].raw_type)
21
+ when 2
20
22
  create_validator_method_fast2(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
21
- method_sig.arg_types[0][1].raw_type,
22
- method_sig.arg_types[1][1].raw_type)
23
- elsif method_sig.arg_types.length == 3
23
+ arg_types[0][1].raw_type,
24
+ arg_types[1][1].raw_type)
25
+ when 3
24
26
  create_validator_method_fast3(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
25
- method_sig.arg_types[0][1].raw_type,
26
- method_sig.arg_types[1][1].raw_type,
27
- method_sig.arg_types[2][1].raw_type)
28
- elsif method_sig.arg_types.length == 4
27
+ arg_types[0][1].raw_type,
28
+ arg_types[1][1].raw_type,
29
+ arg_types[2][1].raw_type)
30
+ when 4
29
31
  create_validator_method_fast4(mod, original_method, method_sig, original_visibility, method_sig.return_type.raw_type,
30
- method_sig.arg_types[0][1].raw_type,
31
- method_sig.arg_types[1][1].raw_type,
32
- method_sig.arg_types[2][1].raw_type,
33
- method_sig.arg_types[3][1].raw_type)
32
+ arg_types[0][1].raw_type,
33
+ arg_types[1][1].raw_type,
34
+ arg_types[2][1].raw_type,
35
+ arg_types[3][1].raw_type)
34
36
  else
35
37
  raise 'should not happen'
36
38
  end
@@ -343,26 +345,28 @@ module T::Private::Methods::CallValidation
343
345
 
344
346
  def self.create_validator_procedure_fast(mod, original_method, method_sig, original_visibility)
345
347
  # trampoline to reduce stack frame size
346
- if method_sig.arg_types.empty?
348
+ arg_types = method_sig.arg_types
349
+ case arg_types.length
350
+ when 0
347
351
  create_validator_procedure_fast0(mod, original_method, method_sig, original_visibility)
348
- elsif method_sig.arg_types.length == 1
352
+ when 1
349
353
  create_validator_procedure_fast1(mod, original_method, method_sig, original_visibility,
350
- method_sig.arg_types[0][1].raw_type)
351
- elsif method_sig.arg_types.length == 2
354
+ arg_types[0][1].raw_type)
355
+ when 2
352
356
  create_validator_procedure_fast2(mod, original_method, method_sig, original_visibility,
353
- method_sig.arg_types[0][1].raw_type,
354
- method_sig.arg_types[1][1].raw_type)
355
- elsif method_sig.arg_types.length == 3
357
+ arg_types[0][1].raw_type,
358
+ arg_types[1][1].raw_type)
359
+ when 3
356
360
  create_validator_procedure_fast3(mod, original_method, method_sig, original_visibility,
357
- method_sig.arg_types[0][1].raw_type,
358
- method_sig.arg_types[1][1].raw_type,
359
- method_sig.arg_types[2][1].raw_type)
360
- elsif method_sig.arg_types.length == 4
361
+ arg_types[0][1].raw_type,
362
+ arg_types[1][1].raw_type,
363
+ arg_types[2][1].raw_type)
364
+ when 4
361
365
  create_validator_procedure_fast4(mod, original_method, method_sig, original_visibility,
362
- method_sig.arg_types[0][1].raw_type,
363
- method_sig.arg_types[1][1].raw_type,
364
- method_sig.arg_types[2][1].raw_type,
365
- method_sig.arg_types[3][1].raw_type)
366
+ arg_types[0][1].raw_type,
367
+ arg_types[1][1].raw_type,
368
+ arg_types[2][1].raw_type,
369
+ arg_types[3][1].raw_type)
366
370
  else
367
371
  raise 'should not happen'
368
372
  end
@@ -608,26 +612,28 @@ module T::Private::Methods::CallValidation
608
612
  raise 'Should have used create_validator_procedure_medium'
609
613
  end
610
614
  # trampoline to reduce stack frame size
611
- if method_sig.arg_types.empty?
615
+ arg_types = method_sig.arg_types
616
+ case arg_types.length
617
+ when 0
612
618
  create_validator_method_medium0(mod, original_method, method_sig, original_visibility, method_sig.return_type)
613
- elsif method_sig.arg_types.length == 1
619
+ when 1
614
620
  create_validator_method_medium1(mod, original_method, method_sig, original_visibility, method_sig.return_type,
615
- method_sig.arg_types[0][1])
616
- elsif method_sig.arg_types.length == 2
621
+ arg_types[0][1])
622
+ when 2
617
623
  create_validator_method_medium2(mod, original_method, method_sig, original_visibility, method_sig.return_type,
618
- method_sig.arg_types[0][1],
619
- method_sig.arg_types[1][1])
620
- elsif method_sig.arg_types.length == 3
624
+ arg_types[0][1],
625
+ arg_types[1][1])
626
+ when 3
621
627
  create_validator_method_medium3(mod, original_method, method_sig, original_visibility, method_sig.return_type,
622
- method_sig.arg_types[0][1],
623
- method_sig.arg_types[1][1],
624
- method_sig.arg_types[2][1])
625
- elsif method_sig.arg_types.length == 4
628
+ arg_types[0][1],
629
+ arg_types[1][1],
630
+ arg_types[2][1])
631
+ when 4
626
632
  create_validator_method_medium4(mod, original_method, method_sig, original_visibility, method_sig.return_type,
627
- method_sig.arg_types[0][1],
628
- method_sig.arg_types[1][1],
629
- method_sig.arg_types[2][1],
630
- method_sig.arg_types[3][1])
633
+ arg_types[0][1],
634
+ arg_types[1][1],
635
+ arg_types[2][1],
636
+ arg_types[3][1])
631
637
  else
632
638
  raise 'should not happen'
633
639
  end
@@ -940,26 +946,28 @@ module T::Private::Methods::CallValidation
940
946
 
941
947
  def self.create_validator_procedure_medium(mod, original_method, method_sig, original_visibility)
942
948
  # trampoline to reduce stack frame size
943
- if method_sig.arg_types.empty?
949
+ arg_types = method_sig.arg_types
950
+ case arg_types.length
951
+ when 0
944
952
  create_validator_procedure_medium0(mod, original_method, method_sig, original_visibility)
945
- elsif method_sig.arg_types.length == 1
953
+ when 1
946
954
  create_validator_procedure_medium1(mod, original_method, method_sig, original_visibility,
947
- method_sig.arg_types[0][1])
948
- elsif method_sig.arg_types.length == 2
955
+ arg_types[0][1])
956
+ when 2
949
957
  create_validator_procedure_medium2(mod, original_method, method_sig, original_visibility,
950
- method_sig.arg_types[0][1],
951
- method_sig.arg_types[1][1])
952
- elsif method_sig.arg_types.length == 3
958
+ arg_types[0][1],
959
+ arg_types[1][1])
960
+ when 3
953
961
  create_validator_procedure_medium3(mod, original_method, method_sig, original_visibility,
954
- method_sig.arg_types[0][1],
955
- method_sig.arg_types[1][1],
956
- method_sig.arg_types[2][1])
957
- elsif method_sig.arg_types.length == 4
962
+ arg_types[0][1],
963
+ arg_types[1][1],
964
+ arg_types[2][1])
965
+ when 4
958
966
  create_validator_procedure_medium4(mod, original_method, method_sig, original_visibility,
959
- method_sig.arg_types[0][1],
960
- method_sig.arg_types[1][1],
961
- method_sig.arg_types[2][1],
962
- method_sig.arg_types[3][1])
967
+ arg_types[0][1],
968
+ arg_types[1][1],
969
+ arg_types[2][1],
970
+ arg_types[3][1])
963
971
  else
964
972
  raise 'should not happen'
965
973
  end
@@ -231,15 +231,17 @@ module T::Private::Methods
231
231
  decl.on_failure = nil
232
232
  end
233
233
  if decl.params.equal?(ARG_NOT_PROVIDED)
234
- decl.params = {}
234
+ decl.params = FROZEN_HASH
235
235
  end
236
236
  if decl.type_parameters.equal?(ARG_NOT_PROVIDED)
237
- decl.type_parameters = {}
237
+ decl.type_parameters = FROZEN_HASH
238
238
  end
239
239
 
240
240
  decl.finalized = true
241
241
 
242
242
  self
243
243
  end
244
+
245
+ FROZEN_HASH = {}.freeze
244
246
  end
245
247
  end