sorbet-runtime 0.5.10439 → 0.5.11120

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sorbet-runtime.rb +7 -1
  3. data/lib/types/_types.rb +57 -3
  4. data/lib/types/compatibility_patches.rb +4 -2
  5. data/lib/types/enum.rb +6 -1
  6. data/lib/types/generic.rb +2 -0
  7. data/lib/types/private/abstract/declare.rb +10 -9
  8. data/lib/types/private/casts.rb +4 -1
  9. data/lib/types/private/class_utils.rb +13 -6
  10. data/lib/types/private/methods/_methods.rb +37 -12
  11. data/lib/types/private/methods/call_validation.rb +104 -5
  12. data/lib/types/private/methods/call_validation_2_6.rb +68 -60
  13. data/lib/types/private/methods/call_validation_2_7.rb +68 -60
  14. data/lib/types/private/methods/decl_builder.rb +21 -6
  15. data/lib/types/private/methods/signature.rb +63 -38
  16. data/lib/types/private/methods/signature_validation.rb +68 -6
  17. data/lib/types/private/runtime_levels.rb +19 -0
  18. data/lib/types/private/types/not_typed.rb +2 -0
  19. data/lib/types/private/types/simple_pair_union.rb +55 -0
  20. data/lib/types/private/types/void.rb +29 -23
  21. data/lib/types/props/_props.rb +2 -2
  22. data/lib/types/props/custom_type.rb +2 -2
  23. data/lib/types/props/decorator.rb +41 -36
  24. data/lib/types/props/has_lazily_specialized_methods.rb +2 -2
  25. data/lib/types/props/pretty_printable.rb +45 -83
  26. data/lib/types/props/private/setter_factory.rb +1 -1
  27. data/lib/types/props/serializable.rb +17 -9
  28. data/lib/types/props/type_validation.rb +5 -2
  29. data/lib/types/struct.rb +2 -2
  30. data/lib/types/types/anything.rb +31 -0
  31. data/lib/types/types/base.rb +15 -1
  32. data/lib/types/types/class_of.rb +11 -0
  33. data/lib/types/types/enum.rb +1 -1
  34. data/lib/types/types/fixed_array.rb +13 -0
  35. data/lib/types/types/fixed_hash.rb +22 -0
  36. data/lib/types/types/intersection.rb +1 -1
  37. data/lib/types/types/noreturn.rb +0 -1
  38. data/lib/types/types/simple.rb +27 -4
  39. data/lib/types/types/type_parameter.rb +19 -0
  40. data/lib/types/types/typed_array.rb +29 -0
  41. data/lib/types/types/typed_class.rb +85 -0
  42. data/lib/types/types/typed_enumerable.rb +7 -0
  43. data/lib/types/types/typed_enumerator_chain.rb +41 -0
  44. data/lib/types/types/union.rb +50 -14
  45. data/lib/types/utils.rb +41 -33
  46. metadata +14 -10
data/lib/types/utils.rb CHANGED
@@ -2,29 +2,41 @@
2
2
  # typed: true
3
3
 
4
4
  module T::Utils
5
+ module Private
6
+ def self.coerce_and_check_module_types(val, check_val, check_module_type)
7
+ if val.is_a?(T::Types::Base)
8
+ if val.is_a?(T::Private::Types::TypeAlias)
9
+ val.aliased_type
10
+ else
11
+ val
12
+ end
13
+ elsif val.is_a?(Module)
14
+ if check_module_type && check_val.is_a?(val)
15
+ nil
16
+ else
17
+ T::Types::Simple::Private::Pool.type_for_module(val)
18
+ end
19
+ elsif val.is_a?(::Array)
20
+ T::Types::FixedArray.new(val)
21
+ elsif val.is_a?(::Hash)
22
+ T::Types::FixedHash.new(val)
23
+ elsif val.is_a?(T::Private::Methods::DeclBuilder)
24
+ T::Private::Methods.finalize_proc(val.decl)
25
+ elsif val.is_a?(::T::Enum)
26
+ T::Types::TEnum.new(val)
27
+ elsif val.is_a?(::String)
28
+ raise "Invalid String literal for type constraint. Must be an #{T::Types::Base}, a " \
29
+ "class/module, or an array. Got a String with value `#{val}`."
30
+ else
31
+ raise "Invalid value for type constraint. Must be an #{T::Types::Base}, a " \
32
+ "class/module, or an array. Got a `#{val.class}`."
33
+ end
34
+ end
35
+ end
36
+
5
37
  # Used to convert from a type specification to a `T::Types::Base`.
6
38
  def self.coerce(val)
7
- if val.is_a?(T::Private::Types::TypeAlias)
8
- val.aliased_type
9
- elsif val.is_a?(T::Types::Base)
10
- val
11
- elsif val.is_a?(Module)
12
- T::Types::Simple::Private::Pool.type_for_module(val)
13
- elsif val.is_a?(::Array)
14
- T::Types::FixedArray.new(val)
15
- elsif val.is_a?(::Hash)
16
- T::Types::FixedHash.new(val)
17
- elsif val.is_a?(T::Private::Methods::DeclBuilder)
18
- T::Private::Methods.finalize_proc(val.decl)
19
- elsif val.is_a?(::T::Enum)
20
- T::Types::TEnum.new(val)
21
- elsif val.is_a?(::String)
22
- raise "Invalid String literal for type constraint. Must be an #{T::Types::Base}, a " \
23
- "class/module, or an array. Got a String with value `#{val}`."
24
- else
25
- raise "Invalid value for type constraint. Must be an #{T::Types::Base}, a " \
26
- "class/module, or an array. Got a `#{val.class}`."
27
- end
39
+ Private.coerce_and_check_module_types(val, nil, false)
28
40
  end
29
41
 
30
42
  # Dynamically confirm that `value` is recursively a valid value of
@@ -86,14 +98,7 @@ module T::Utils
86
98
  def self.unwrap_nilable(type)
87
99
  case type
88
100
  when T::Types::Union
89
- non_nil_types = type.types.reject {|t| t == Nilable::NIL_TYPE}
90
- return nil if type.types.length == non_nil_types.length
91
- case non_nil_types.length
92
- when 0 then nil
93
- when 1 then non_nil_types.first
94
- else
95
- T::Types::Union::Private::Pool.union_of_types(non_nil_types[0], non_nil_types[1], non_nil_types[2..-1])
96
- end
101
+ type.unwrap_nilable
97
102
  else
98
103
  nil
99
104
  end
@@ -167,7 +172,7 @@ module T::Utils
167
172
 
168
173
  def self.get_type_info(prop_type)
169
174
  if prop_type.is_a?(T::Types::Union)
170
- non_nilable_type = T::Utils.unwrap_nilable(prop_type)
175
+ non_nilable_type = prop_type.unwrap_nilable
171
176
  if non_nilable_type&.is_a?(T::Types::Simple)
172
177
  non_nilable_type = non_nilable_type.raw_type
173
178
  end
@@ -181,9 +186,12 @@ module T::Utils
181
186
  # - if the type is A, the function returns A
182
187
  # - if the type is T.nilable(A), the function returns A
183
188
  def self.get_underlying_type(prop_type)
184
- type_info = get_type_info(prop_type)
185
- if type_info.is_union_type
186
- type_info.non_nilable_type || prop_type
189
+ if prop_type.is_a?(T::Types::Union)
190
+ non_nilable_type = prop_type.unwrap_nilable
191
+ if non_nilable_type&.is_a?(T::Types::Simple)
192
+ non_nilable_type = non_nilable_type.raw_type
193
+ end
194
+ non_nilable_type || prop_type
187
195
  elsif prop_type.is_a?(T::Types::Simple)
188
196
  prop_type.raw_type
189
197
  else
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.10439
4
+ version: 0.5.11120
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-17 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.5.3
153
153
  description: Sorbet's runtime type checking component
154
- email:
154
+ email:
155
155
  executables: []
156
156
  extensions: []
157
157
  extra_rdoc_files: []
@@ -189,6 +189,7 @@ files:
189
189
  - lib/types/private/runtime_levels.rb
190
190
  - lib/types/private/sealed.rb
191
191
  - lib/types/private/types/not_typed.rb
192
+ - lib/types/private/types/simple_pair_union.rb
192
193
  - lib/types/private/types/string_holder.rb
193
194
  - lib/types/private/types/type_alias.rb
194
195
  - lib/types/private/types/void.rb
@@ -214,6 +215,7 @@ files:
214
215
  - lib/types/props/weak_constructor.rb
215
216
  - lib/types/sig.rb
216
217
  - lib/types/struct.rb
218
+ - lib/types/types/anything.rb
217
219
  - lib/types/types/attached_class.rb
218
220
  - lib/types/types/base.rb
219
221
  - lib/types/types/class_of.rb
@@ -231,8 +233,10 @@ files:
231
233
  - lib/types/types/type_template.rb
232
234
  - lib/types/types/type_variable.rb
233
235
  - lib/types/types/typed_array.rb
236
+ - lib/types/types/typed_class.rb
234
237
  - lib/types/types/typed_enumerable.rb
235
238
  - lib/types/types/typed_enumerator.rb
239
+ - lib/types/types/typed_enumerator_chain.rb
236
240
  - lib/types/types/typed_enumerator_lazy.rb
237
241
  - lib/types/types/typed_hash.rb
238
242
  - lib/types/types/typed_range.rb
@@ -245,7 +249,7 @@ licenses:
245
249
  - Apache-2.0
246
250
  metadata:
247
251
  source_code_uri: https://github.com/sorbet/sorbet
248
- post_install_message:
252
+ post_install_message:
249
253
  rdoc_options: []
250
254
  require_paths:
251
255
  - lib
@@ -253,15 +257,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
257
  requirements:
254
258
  - - ">="
255
259
  - !ruby/object:Gem::Version
256
- version: 2.3.0
260
+ version: 2.7.0
257
261
  required_rubygems_version: !ruby/object:Gem::Requirement
258
262
  requirements:
259
263
  - - ">="
260
264
  - !ruby/object:Gem::Version
261
265
  version: '0'
262
266
  requirements: []
263
- rubygems_version: 3.1.4
264
- signing_key:
267
+ rubygems_version: 3.3.7
268
+ signing_key:
265
269
  specification_version: 4
266
270
  summary: Sorbet runtime
267
271
  test_files: []