sorbet-runtime 0.5.10676 → 0.5.10685

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: 7af4dd278e99d924889ddfc3e61d864a109755a805bd516a0ec94b9af59226fd
4
- data.tar.gz: f09610bc852ac70b0fed6e6934b63c981aec7302e78cc1ae918c09018de6d062
3
+ metadata.gz: 8abe95455ceb7a84913b970b24f57ebc52e5a90739acc842d63cc77006a32cb8
4
+ data.tar.gz: fd9669b6dc7e49027ee59020438e20485a72859fb025d9ffd4c4c677e572ada2
5
5
  SHA512:
6
- metadata.gz: 6c3b30eeaa8b157178a64a1c479e372e767baa2932d4da6e78ae0322fdb1691b82d28628f17f3a5f976ce25326fa77e0b14eb5390d075c9dac47ac57db2f55a1
7
- data.tar.gz: 4de95cdb730556c7401ab29b012b150e1a787cbe4e9fd65365f1d604f4c96d7375364eb31c5f85f2c84aa3ba5fba3a35056b8aebed270b138aec4c8945732c1e
6
+ metadata.gz: 91ae0fd7fe69a00f6bb7bb88972239971bb375488a95f910c094059140b36b019ac72560dae8eecb01d253fb3e4e2c2bd5ad2bf8e18de8e643f8292a003c4069
7
+ data.tar.gz: '069f75ea34202692746d176cf00ee4177534a3b972fbe432a20df8d9310ee8466ae487f15415c8480aa83342f5ebf8113ee6ed239454ba88dbdf460ef6e9c25b'
data/lib/types/enum.rb CHANGED
@@ -362,6 +362,11 @@ class T::Enum
362
362
  super
363
363
 
364
364
  raise "Inheriting from children of T::Enum is prohibited" if self != T::Enum
365
+
366
+ # "oj" gem JSON support
367
+ if Object.const_defined?(:Oj)
368
+ Object.const_get(:Oj).register_odd(child_class, child_class, :try_deserialize, :serialize)
369
+ end
365
370
  end
366
371
 
367
372
  # Marshal support
@@ -83,7 +83,7 @@ module T::Private::Methods
83
83
  raise "Procs cannot have override/abstract modifiers"
84
84
  end
85
85
  if decl.mod != PROC_TYPE
86
- raise "You are passing a DeclBuilder as a type. Did you accidentally use `self` inside a `sig` block?"
86
+ raise "You are passing a DeclBuilder as a type. Did you accidentally use `self` inside a `sig` block? Perhaps you wanted the `T.self_type` instead: https://sorbet.org/docs/self-type"
87
87
  end
88
88
  if decl.returns == ARG_NOT_PROVIDED
89
89
  raise "Procs must specify a return type"
@@ -39,4 +39,17 @@ class T::Private::Types::SimplePairUnion < T::Types::Union
39
39
  T::Types::Simple::Private::Pool.type_for_module(@raw_b),
40
40
  ]
41
41
  end
42
+
43
+ # overrides Union
44
+ def unwrap_nilable
45
+ a_nil = @raw_a.equal?(NilClass)
46
+ b_nil = @raw_b.equal?(NilClass)
47
+ if a_nil
48
+ return types[1]
49
+ end
50
+ if b_nil
51
+ return types[0]
52
+ end
53
+ nil
54
+ end
42
55
  end
@@ -54,6 +54,12 @@ module T::Types
54
54
  return t1.aliased_type.subtype_of?(t2)
55
55
  end
56
56
 
57
+ if t1.is_a?(T::Types::TypeVariable) || t2.is_a?(T::Types::TypeVariable)
58
+ # Generics are erased at runtime. Let's treat them like `T.untyped` for
59
+ # the purpose of things like override checking.
60
+ return true
61
+ end
62
+
57
63
  # pairs to cover: 1 (_, _)
58
64
  # 2 (_, And)
59
65
  # 3 (_, Or)
@@ -64,6 +64,17 @@ module T::Types
64
64
  raise "This should never be reached if you're going through `subtype_of?` (and you should be)"
65
65
  end
66
66
 
67
+ def unwrap_nilable
68
+ non_nil_types = types.reject {|t| t == T::Utils::Nilable::NIL_TYPE}
69
+ return nil if types.length == non_nil_types.length
70
+ case non_nil_types.length
71
+ when 0 then nil
72
+ when 1 then non_nil_types.first
73
+ else
74
+ T::Types::Union::Private::Pool.union_of_types(non_nil_types[0], non_nil_types[1], non_nil_types[2..-1])
75
+ end
76
+ end
77
+
67
78
  module Private
68
79
  module Pool
69
80
  EMPTY_ARRAY = [].freeze
data/lib/types/utils.rb CHANGED
@@ -98,14 +98,7 @@ module T::Utils
98
98
  def self.unwrap_nilable(type)
99
99
  case type
100
100
  when T::Types::Union
101
- non_nil_types = type.types.reject {|t| t == Nilable::NIL_TYPE}
102
- return nil if type.types.length == non_nil_types.length
103
- case non_nil_types.length
104
- when 0 then nil
105
- when 1 then non_nil_types.first
106
- else
107
- T::Types::Union::Private::Pool.union_of_types(non_nil_types[0], non_nil_types[1], non_nil_types[2..-1])
108
- end
101
+ type.unwrap_nilable
109
102
  else
110
103
  nil
111
104
  end
@@ -179,7 +172,7 @@ module T::Utils
179
172
 
180
173
  def self.get_type_info(prop_type)
181
174
  if prop_type.is_a?(T::Types::Union)
182
- non_nilable_type = T::Utils.unwrap_nilable(prop_type)
175
+ non_nilable_type = prop_type.unwrap_nilable
183
176
  if non_nilable_type&.is_a?(T::Types::Simple)
184
177
  non_nilable_type = non_nilable_type.raw_type
185
178
  end
@@ -193,9 +186,12 @@ module T::Utils
193
186
  # - if the type is A, the function returns A
194
187
  # - if the type is T.nilable(A), the function returns A
195
188
  def self.get_underlying_type(prop_type)
196
- type_info = get_type_info(prop_type)
197
- if type_info.is_union_type
198
- 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
199
195
  elsif prop_type.is_a?(T::Types::Simple)
200
196
  prop_type.raw_type
201
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.10676
4
+ version: 0.5.10685
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-18 00:00:00.000000000 Z
11
+ date: 2023-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest