sorbet-runtime 0.5.10549 → 0.5.10554

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: f2fdc4fdb96e9556c22604c97387f6b1ab2c2e9c34a2d41d407ce7ebb1555e12
4
- data.tar.gz: e291af767e4d453b043c57c9be3e895aee893b5ab455f5b3c39dfbf2ae8aee4f
3
+ metadata.gz: b4c908175afeef1638f97498f321a86aa856e679b5c47fafe7d6e1b58d14c46b
4
+ data.tar.gz: 0f851edf84269ea09592e5f8b47e43e7f1e014fde5f8623e742559c2000b83ff
5
5
  SHA512:
6
- metadata.gz: 39fc2a848602fcbafee6bda31f7d2f46dbacaecfa970bd9e846f47220be4517313070e1c6516af05c5fbc3bc26438fd14ef041d007a2cadf11d192ae1fe14a75
7
- data.tar.gz: 79ded3d9e594508f394da18fd42fc5d7cc5176697cacf5dbc7a876219e4a58af02b329d7212a07d272da3fbaf1e5039356ba85436794cc0e34ffcd3846be4b18
6
+ metadata.gz: 5c62e04a5719e9a79e8d4c0421d0dd5c87452bbc1e1304db138a20e36749295f54a6e93d8b75a502a4a635242bba8c8d6d68460fa8ac1faad5368bd18246f609
7
+ data.tar.gz: b02a1269079cf44fea21ae4c13b13d1b3a9ebf0a848fb49da9e94c219b560b74b3f1e5723b5667f678fe5abef5b806dd7ebc0689f765098e6c801bb08c25d719
@@ -5,7 +5,10 @@ module T::Private
5
5
  module Casts
6
6
  def self.cast(value, type, cast_method)
7
7
  begin
8
- error = T::Utils.coerce(type).error_message_for_obj(value)
8
+ coerced_type = T::Utils::Private.coerce_and_check_module_types(type, value, true)
9
+ return value unless coerced_type
10
+
11
+ error = coerced_type.error_message_for_obj(value)
9
12
  return value unless error
10
13
 
11
14
  caller_loc = T.must(caller_locations(2..2)).first
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
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.10549
4
+ version: 0.5.10554
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-10 00:00:00.000000000 Z
11
+ date: 2022-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest