sorbet-runtime 0.5.10672 → 0.5.10679

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: 5bccbb8729d362e4f7baf45a69df1d628927c73ccda509e2afd79657c9ab5563
4
- data.tar.gz: 88eecc1e4cf6de6726bc85c27654f36c7036a8bc5bea401848ed7bf047c80fd7
3
+ metadata.gz: 10e2f25720f79e5e0ab5bfb00abc030dc87c73be629112c11d8844f89726a4a3
4
+ data.tar.gz: b05c04621a3779ded3f6000abaaf1a69aba85a4f73c3310e445d334e90f505c8
5
5
  SHA512:
6
- metadata.gz: d63610594e239324c862c1f86e2d2d4ba7db74035e64af3f0c701bed333e000718dacc4cfc8198e1c9db5dc66112ff17f714fbca97ffd21ee256f701de519ae4
7
- data.tar.gz: 7f6298a6d1d0e297954b924d49f750142438114c072e5b39f171eafdd02da8e001853b76a7b7c418939d225102792a69c72c7154bb4b4addef45c476c8412cd6
6
+ metadata.gz: c87d22bce8fc6ccd7e001a54d625465a15a0a3d004a92d9cb2f7f2db233adbd339974bb281a242fa0fe4f2181b34201714da546bae40143e701480c6772cca97
7
+ data.tar.gz: 1756ba572c0bf4cd6a0915d1b085bb5fa2bc3cdfaced16babc0098c5750bab76829e5b8b1cef322418ee654363b3d0afc265f52b0f107d60e62d8210d208ada5
@@ -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)
@@ -59,6 +59,19 @@ module T::Types
59
59
  @types.size == other.types.size && @types.zip(other.types).all? do |t1, t2|
60
60
  t1.subtype_of?(t2)
61
61
  end
62
+ when TypedArray
63
+ # warning: covariant arrays
64
+
65
+ value1, value2, *values_rest = types
66
+ value_type = if !value2.nil?
67
+ T::Types::Union::Private::Pool.union_of_types(value1, value2, values_rest)
68
+ elsif value1.nil?
69
+ T.untyped
70
+ else
71
+ value1
72
+ end
73
+
74
+ T::Types::TypedArray.new(value_type).subtype_of?(other)
62
75
  else
63
76
  false
64
77
  end
@@ -38,6 +38,28 @@ module T::Types
38
38
  when FixedHash
39
39
  # Using `subtype_of?` here instead of == would be unsound
40
40
  @types == other.types
41
+ when TypedHash
42
+ # warning: covariant hashes
43
+
44
+ key1, key2, *keys_rest = types.keys.map {|key| T::Utils.coerce(key.class)}
45
+ key_type = if !key2.nil?
46
+ T::Types::Union::Private::Pool.union_of_types(key1, key2, keys_rest)
47
+ elsif key1.nil?
48
+ T.untyped
49
+ else
50
+ key1
51
+ end
52
+
53
+ value1, value2, *values_rest = types.values
54
+ value_type = if !value2.nil?
55
+ T::Types::Union::Private::Pool.union_of_types(value1, value2, values_rest)
56
+ elsif value1.nil?
57
+ T.untyped
58
+ else
59
+ value1
60
+ end
61
+
62
+ T::Types::TypedHash.new(keys: key_type, values: value_type).subtype_of?(other)
41
63
  else
42
64
  false
43
65
  end
@@ -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.10672
4
+ version: 0.5.10679
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-17 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest