sorbet-runtime 0.5.5651 → 0.5.5657

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: 181d169545984c142df587bedf3995e13a6c18c15b59fb04816e712104a11dc3
4
- data.tar.gz: 47fecc926152e65fd6db14c2df9ed8f870105272bc09c07ef9bbf11e2748aade
3
+ metadata.gz: 04dbb8ac655032897af8b72e52e41e60bbb08d471e1bb3257422b0f765eca12e
4
+ data.tar.gz: 7e661cde9f4fefc762c72875b320c54da69971f96a0906137ed1c398aea4c9bd
5
5
  SHA512:
6
- metadata.gz: a741a233e4bc0e8b4efb1b0fdbaa785c361828ff8eb93d7effc1e90cdfc4166b6aa0e4e1356487294b33049ecefd070b060bf46b307172f787181b55223419b6
7
- data.tar.gz: 85ba00d5ed36916c261d5d1ccb752def465eb4276a230477135f995b47c7fb180d53dd15262d2b9d5d85a5a0682f6bdfabe7ccd3d0d80c874025bdf710cec096
6
+ metadata.gz: 4c7c50b7f66658e4e427629bcc881ddb9c7cf987c00b4a06e91c871c7e4105354811a4f6c40d72649a605b178ed8b7896f539f7329c30e6860ef8378964ce48b
7
+ data.tar.gz: 07d5d1764063df2a278a0eb16363756cf33d12afb19ea10727a77600787238b3219661b1c0113d4b3a90f970c245da3953df21254b2eccd494f3da2f8c8390f7
@@ -220,12 +220,6 @@ class T::Props::Decorator
220
220
  raise ArgumentError.new("At least one invalid prop arg supplied in #{self}: #{rules.keys.inspect}")
221
221
  end
222
222
 
223
- if (array = rules[:array])
224
- unless array.is_a?(Module)
225
- raise ArgumentError.new("Bad class as subtype in prop #{@class.name}.#{name}: #{array.inspect}")
226
- end
227
- end
228
-
229
223
  if !(rules[:clobber_existing_method!]) && !(rules[:without_accessors])
230
224
  if BANNED_METHOD_NAMES.include?(name.to_sym)
231
225
  raise ArgumentError.new(
@@ -350,7 +344,7 @@ class T::Props::Decorator
350
344
  if !cls.is_a?(Module)
351
345
  cls = convert_type_to_class(cls)
352
346
  end
353
- type_object = smart_coerce(type, array: rules[:array], enum: rules[:enum])
347
+ type_object = smart_coerce(type, enum: rules[:enum])
354
348
 
355
349
  prop_validate_definition!(name, cls, rules, type_object)
356
350
 
@@ -441,27 +435,21 @@ class T::Props::Decorator
441
435
  end
442
436
 
443
437
  sig do
444
- params(type: PropTypeOrClass, array: T.untyped, enum: T.untyped)
438
+ params(type: PropTypeOrClass, enum: T.untyped)
445
439
  .returns(T::Types::Base)
446
440
  end
447
- private def smart_coerce(type, array:, enum:)
441
+ private def smart_coerce(type, enum:)
448
442
  # Backwards compatibility for pre-T::Types style
449
- if !array.nil? && !enum.nil?
450
- raise ArgumentError.new("Cannot specify both :array and :enum options")
451
- elsif !array.nil?
452
- if type == Set
453
- T::Set[array]
454
- else
455
- T::Array[array]
456
- end
457
- elsif !enum.nil?
458
- if T::Utils.unwrap_nilable(type)
459
- T.nilable(T.enum(enum))
443
+ type = T::Utils.coerce(type)
444
+ if enum.nil?
445
+ type
446
+ else
447
+ nonnil_type = T::Utils.unwrap_nilable(type)
448
+ if nonnil_type
449
+ T.nilable(T.all(nonnil_type, T.enum(enum)))
460
450
  else
461
- T.enum(enum)
451
+ T.all(type, T.enum(enum))
462
452
  end
463
- else
464
- T::Utils.coerce(type)
465
453
  end
466
454
  end
467
455
 
@@ -99,6 +99,38 @@ module T::Props
99
99
  "T::Props::Utils.deep_clone_object(#{varname})"
100
100
  end
101
101
  end
102
+ when T::Types::Intersection
103
+ dynamic_fallback = "T::Props::Utils.deep_clone_object(#{varname})"
104
+
105
+ # Transformations for any members of the intersection type where we
106
+ # know what we need to do and did not have to fall back to the
107
+ # dynamic deep clone method.
108
+ #
109
+ # NB: This deliberately does include `nil`, which means we know we
110
+ # don't need to do any transforming.
111
+ inner_known = type.types
112
+ .map {|t| generate(t, mode, varname)}
113
+ .reject {|t| t == dynamic_fallback}
114
+ .uniq
115
+
116
+ if inner_known.size != 1
117
+ # If there were no cases where we could tell what we need to do,
118
+ # e.g. if this is `T.all(SomethingWeird, WhoKnows)`, just use the
119
+ # dynamic fallback.
120
+ #
121
+ # If there were multiple cases and they weren't consistent, e.g.
122
+ # if this is `T.all(String, T::Array[Integer])`, the type is probably
123
+ # bogus/uninhabited, but use the dynamic fallback because we still
124
+ # don't have a better option, and this isn't the place to raise that
125
+ # error.
126
+ dynamic_fallback
127
+ else
128
+ # This is probably something like `T.all(String, SomeMarker)` or
129
+ # `T.all(SomeEnum, T.enum(SomeEnum::FOO))` and we should treat it
130
+ # like String or SomeEnum even if we don't know what to do with
131
+ # the rest of the type.
132
+ inner_known.first
133
+ end
102
134
  when T::Types::Enum
103
135
  generate(T::Utils.lift_enum(type), mode, varname)
104
136
  else
@@ -63,7 +63,16 @@ module T::Props::TypeValidation
63
63
  when T::Types::FixedHash
64
64
  type.types.values.map {|subtype| find_invalid_subtype(subtype)}.compact.first
65
65
  when T::Types::Union, T::Types::FixedArray
66
+ # `T.any` is valid if all of the members are valid
66
67
  type.types.map {|subtype| find_invalid_subtype(subtype)}.compact.first
68
+ when T::Types::Intersection
69
+ # `T.all` is valid if at least one of the members is valid
70
+ invalid = type.types.map {|subtype| find_invalid_subtype(subtype)}.compact
71
+ if invalid.length == type.types.length
72
+ invalid.first
73
+ else
74
+ nil
75
+ end
67
76
  when T::Types::Enum, T::Types::ClassOf
68
77
  nil
69
78
  when T::Private::Types::TypeAlias
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.5651
4
+ version: 0.5.5657
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest