sorbet-runtime 0.5.11144 → 0.5.11663
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sorbet-runtime.rb +1 -4
- data/lib/types/compatibility_patches.rb +1 -1
- data/lib/types/configuration.rb +3 -2
- data/lib/types/enum.rb +63 -39
- data/lib/types/non_forcing_constants.rb +4 -14
- data/lib/types/private/abstract/declare.rb +4 -5
- data/lib/types/private/caller_utils.rb +27 -0
- data/lib/types/private/class_utils.rb +1 -1
- data/lib/types/private/methods/_methods.rb +35 -30
- data/lib/types/private/methods/call_validation.rb +48 -16
- data/lib/types/private/methods/call_validation_2_6.rb +518 -0
- data/lib/types/private/methods/call_validation_2_7.rb +518 -0
- data/lib/types/private/methods/decl_builder.rb +4 -4
- data/lib/types/private/methods/signature.rb +10 -2
- data/lib/types/private/methods/signature_validation.rb +13 -7
- data/lib/types/private/runtime_levels.rb +0 -3
- data/lib/types/private/sealed.rb +8 -8
- data/lib/types/private/types/not_typed.rb +4 -0
- data/lib/types/private/types/string_holder.rb +4 -0
- data/lib/types/private/types/type_alias.rb +4 -0
- data/lib/types/private/types/void.rb +4 -0
- data/lib/types/props/_props.rb +3 -3
- data/lib/types/props/decorator.rb +9 -8
- data/lib/types/props/has_lazily_specialized_methods.rb +5 -1
- data/lib/types/props/pretty_printable.rb +7 -7
- data/lib/types/props/private/deserializer_generator.rb +4 -1
- data/lib/types/props/private/setter_factory.rb +129 -69
- data/lib/types/props/serializable.rb +24 -3
- data/lib/types/struct.rb +1 -1
- data/lib/types/types/anything.rb +4 -0
- data/lib/types/types/attached_class.rb +4 -0
- data/lib/types/types/base.rb +8 -2
- data/lib/types/types/class_of.rb +6 -2
- data/lib/types/types/enum.rb +5 -1
- data/lib/types/types/fixed_array.rb +19 -12
- data/lib/types/types/fixed_hash.rb +16 -9
- data/lib/types/types/intersection.rb +13 -6
- data/lib/types/types/noreturn.rb +4 -0
- data/lib/types/types/proc.rb +19 -9
- data/lib/types/types/self_type.rb +4 -0
- data/lib/types/types/simple.rb +9 -0
- data/lib/types/types/t_enum.rb +4 -0
- data/lib/types/types/type_parameter.rb +4 -0
- data/lib/types/types/type_variable.rb +4 -0
- data/lib/types/types/typed_array.rb +7 -2
- data/lib/types/types/typed_class.rb +22 -5
- data/lib/types/types/typed_enumerable.rb +22 -16
- data/lib/types/types/typed_enumerator.rb +2 -4
- data/lib/types/types/typed_enumerator_chain.rb +2 -4
- data/lib/types/types/typed_enumerator_lazy.rb +2 -4
- data/lib/types/types/typed_hash.rb +17 -7
- data/lib/types/types/typed_range.rb +2 -4
- data/lib/types/types/typed_set.rb +3 -5
- data/lib/types/types/union.rb +12 -5
- data/lib/types/types/untyped.rb +4 -0
- data/lib/types/utils.rb +7 -5
- metadata +23 -24
- data/lib/types/interface_wrapper.rb +0 -162
- data/lib/types/private/compiler.rb +0 -24
@@ -5,30 +5,37 @@ module T::Types
|
|
5
5
|
# Takes a hash of types. Validates each item in a hash using the type in the same position
|
6
6
|
# in the list.
|
7
7
|
class FixedHash < Base
|
8
|
-
attr_reader :types
|
9
|
-
|
10
8
|
def initialize(types)
|
11
|
-
@
|
9
|
+
@inner_types = types
|
10
|
+
end
|
11
|
+
|
12
|
+
def types
|
13
|
+
@types ||= @inner_types.transform_values {|v| T::Utils.coerce(v)}
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_type
|
17
|
+
types
|
18
|
+
nil
|
12
19
|
end
|
13
20
|
|
14
21
|
# overrides Base
|
15
22
|
def name
|
16
|
-
serialize_hash(
|
23
|
+
serialize_hash(types)
|
17
24
|
end
|
18
25
|
|
19
26
|
# overrides Base
|
20
27
|
def recursively_valid?(obj)
|
21
28
|
return false unless obj.is_a?(Hash)
|
22
|
-
return false if
|
23
|
-
return false if obj.any? {|key, _|
|
29
|
+
return false if types.any? {|key, type| !type.recursively_valid?(obj[key])}
|
30
|
+
return false if obj.any? {|key, _| !types[key]}
|
24
31
|
true
|
25
32
|
end
|
26
33
|
|
27
34
|
# overrides Base
|
28
35
|
def valid?(obj)
|
29
36
|
return false unless obj.is_a?(Hash)
|
30
|
-
return false if
|
31
|
-
return false if obj.any? {|key, _|
|
37
|
+
return false if types.any? {|key, type| !type.valid?(obj[key])}
|
38
|
+
return false if obj.any? {|key, _| !types[key]}
|
32
39
|
true
|
33
40
|
end
|
34
41
|
|
@@ -37,7 +44,7 @@ module T::Types
|
|
37
44
|
case other
|
38
45
|
when FixedHash
|
39
46
|
# Using `subtype_of?` here instead of == would be unsound
|
40
|
-
|
47
|
+
types == other.types
|
41
48
|
when TypedHash
|
42
49
|
# warning: covariant hashes
|
43
50
|
|
@@ -4,10 +4,12 @@
|
|
4
4
|
module T::Types
|
5
5
|
# Takes a list of types. Validates that an object matches all of the types.
|
6
6
|
class Intersection < Base
|
7
|
-
attr_reader :types
|
8
|
-
|
9
7
|
def initialize(types)
|
10
|
-
@
|
8
|
+
@inner_types = types
|
9
|
+
end
|
10
|
+
|
11
|
+
def types
|
12
|
+
@types ||= @inner_types.flat_map do |type|
|
11
13
|
type = T::Utils.resolve_alias(type)
|
12
14
|
if type.is_a?(Intersection)
|
13
15
|
# Simplify nested intersections (mostly so `name` returns a nicer value)
|
@@ -18,19 +20,24 @@ module T::Types
|
|
18
20
|
end.uniq
|
19
21
|
end
|
20
22
|
|
23
|
+
def build_type
|
24
|
+
types
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
21
28
|
# overrides Base
|
22
29
|
def name
|
23
|
-
"T.all(#{
|
30
|
+
"T.all(#{types.map(&:name).compact.sort.join(', ')})"
|
24
31
|
end
|
25
32
|
|
26
33
|
# overrides Base
|
27
34
|
def recursively_valid?(obj)
|
28
|
-
|
35
|
+
types.all? {|type| type.recursively_valid?(obj)}
|
29
36
|
end
|
30
37
|
|
31
38
|
# overrides Base
|
32
39
|
def valid?(obj)
|
33
|
-
|
40
|
+
types.all? {|type| type.valid?(obj)}
|
34
41
|
end
|
35
42
|
|
36
43
|
# overrides Base
|
data/lib/types/types/noreturn.rb
CHANGED
data/lib/types/types/proc.rb
CHANGED
@@ -8,21 +8,31 @@ module T::Types
|
|
8
8
|
# At present, we only support fixed-arity procs with no optional or
|
9
9
|
# keyword arguments.
|
10
10
|
class Proc < Base
|
11
|
-
attr_reader :arg_types
|
12
|
-
attr_reader :returns
|
13
|
-
|
14
11
|
def initialize(arg_types, returns)
|
15
|
-
@
|
16
|
-
|
17
|
-
|
12
|
+
@inner_arg_types = arg_types
|
13
|
+
@inner_returns = returns
|
14
|
+
end
|
15
|
+
|
16
|
+
def arg_types
|
17
|
+
@arg_types ||= @inner_arg_types.transform_values do |raw_type|
|
18
|
+
T::Utils.coerce(raw_type)
|
18
19
|
end
|
19
|
-
|
20
|
+
end
|
21
|
+
|
22
|
+
def returns
|
23
|
+
@returns ||= T::Utils.coerce(@inner_returns)
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_type
|
27
|
+
arg_types
|
28
|
+
returns
|
29
|
+
nil
|
20
30
|
end
|
21
31
|
|
22
32
|
# overrides Base
|
23
33
|
def name
|
24
34
|
args = []
|
25
|
-
|
35
|
+
arg_types.each do |k, v|
|
26
36
|
args << "#{k}: #{v.name}"
|
27
37
|
end
|
28
38
|
"T.proc.params(#{args.join(', ')}).returns(#{returns})"
|
@@ -41,7 +51,7 @@ module T::Types
|
|
41
51
|
return false
|
42
52
|
end
|
43
53
|
arg_types.values.zip(other.arg_types.values).all? do |a, b|
|
44
|
-
b.subtype_of?(a)
|
54
|
+
!b.nil? && b.subtype_of?(a)
|
45
55
|
end && returns.subtype_of?(other.returns)
|
46
56
|
else
|
47
57
|
false
|
data/lib/types/types/simple.rb
CHANGED
@@ -13,13 +13,22 @@ module T::Types
|
|
13
13
|
@raw_type = raw_type
|
14
14
|
end
|
15
15
|
|
16
|
+
def build_type
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
16
20
|
# overrides Base
|
17
21
|
def name
|
18
22
|
# Memoize to mitigate pathological performance with anonymous modules (https://bugs.ruby-lang.org/issues/11119)
|
19
23
|
#
|
20
24
|
# `name` isn't normally a hot path for types, but it is used in initializing a T::Types::Union,
|
21
25
|
# and so in `T.nilable`, and so in runtime constructions like `x = T.let(nil, T.nilable(Integer))`.
|
26
|
+
#
|
27
|
+
# Care more about back compat than we do about performance here.
|
28
|
+
# Once 2.6 is well in the rear view mirror, we can replace this.
|
29
|
+
# rubocop:disable Performance/BindCall
|
22
30
|
@name ||= (NAME_METHOD.bind(@raw_type).call || @raw_type.name).freeze
|
31
|
+
# rubocop:enable Performance/BindCall
|
23
32
|
end
|
24
33
|
|
25
34
|
# overrides Base
|
data/lib/types/types/t_enum.rb
CHANGED
@@ -5,7 +5,7 @@ module T::Types
|
|
5
5
|
class TypedArray < TypedEnumerable
|
6
6
|
# overrides Base
|
7
7
|
def name
|
8
|
-
"T::Array[#{
|
8
|
+
"T::Array[#{type.name}]"
|
9
9
|
end
|
10
10
|
|
11
11
|
def underlying_class
|
@@ -53,13 +53,18 @@ module T::Types
|
|
53
53
|
|
54
54
|
class Untyped < TypedArray
|
55
55
|
def initialize
|
56
|
-
super(T
|
56
|
+
super(T::Types::Untyped::Private::INSTANCE)
|
57
57
|
end
|
58
58
|
|
59
59
|
def valid?(obj)
|
60
60
|
obj.is_a?(Array)
|
61
61
|
end
|
62
62
|
|
63
|
+
def freeze
|
64
|
+
build_type # force lazy initialization before freezing the object
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
63
68
|
module Private
|
64
69
|
INSTANCE = Untyped.new.freeze
|
65
70
|
end
|
@@ -3,15 +3,22 @@
|
|
3
3
|
|
4
4
|
module T::Types
|
5
5
|
class TypedClass < T::Types::Base
|
6
|
-
attr_reader :type
|
7
|
-
|
8
6
|
def initialize(type)
|
9
|
-
@
|
7
|
+
@inner_type = type
|
8
|
+
end
|
9
|
+
|
10
|
+
def type
|
11
|
+
@type ||= T::Utils.coerce(@inner_type)
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_type
|
15
|
+
type
|
16
|
+
nil
|
10
17
|
end
|
11
18
|
|
12
19
|
# overrides Base
|
13
20
|
def name
|
14
|
-
"T::Class[#{
|
21
|
+
"T::Class[#{type.name}]"
|
15
22
|
end
|
16
23
|
|
17
24
|
def underlying_class
|
@@ -64,7 +71,12 @@ module T::Types
|
|
64
71
|
|
65
72
|
class Untyped < TypedClass
|
66
73
|
def initialize
|
67
|
-
super(T
|
74
|
+
super(T::Types::Untyped::Private::INSTANCE)
|
75
|
+
end
|
76
|
+
|
77
|
+
def freeze
|
78
|
+
build_type # force lazy initialization before freezing the object
|
79
|
+
super
|
68
80
|
end
|
69
81
|
|
70
82
|
module Private
|
@@ -77,6 +89,11 @@ module T::Types
|
|
77
89
|
super(T.anything)
|
78
90
|
end
|
79
91
|
|
92
|
+
def freeze
|
93
|
+
build_type # force lazy initialization before freezing the object
|
94
|
+
super
|
95
|
+
end
|
96
|
+
|
80
97
|
module Private
|
81
98
|
INSTANCE = Anything.new.freeze
|
82
99
|
end
|
@@ -6,10 +6,17 @@ module T::Types
|
|
6
6
|
# `case` statement below in `describe_obj` in order to get better
|
7
7
|
# error messages.
|
8
8
|
class TypedEnumerable < Base
|
9
|
-
attr_reader :type
|
10
|
-
|
11
9
|
def initialize(type)
|
12
|
-
@
|
10
|
+
@inner_type = type
|
11
|
+
end
|
12
|
+
|
13
|
+
def type
|
14
|
+
@type ||= T::Utils.coerce(@inner_type)
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_type
|
18
|
+
type
|
19
|
+
nil
|
13
20
|
end
|
14
21
|
|
15
22
|
def underlying_class
|
@@ -18,7 +25,7 @@ module T::Types
|
|
18
25
|
|
19
26
|
# overrides Base
|
20
27
|
def name
|
21
|
-
"T::Enumerable[#{
|
28
|
+
"T::Enumerable[#{type.name}]"
|
22
29
|
end
|
23
30
|
|
24
31
|
# overrides Base
|
@@ -34,20 +41,19 @@ module T::Types
|
|
34
41
|
begin
|
35
42
|
it = 0
|
36
43
|
while it < obj.count
|
37
|
-
return false unless
|
44
|
+
return false unless type.recursively_valid?(obj[it])
|
38
45
|
it += 1
|
39
46
|
end
|
40
47
|
true
|
41
48
|
end
|
42
49
|
when Hash
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
key_type
|
47
|
-
value_type = types[1]
|
50
|
+
type_ = self.type
|
51
|
+
return false unless type_.is_a?(FixedArray)
|
52
|
+
key_type, value_type = type_.types
|
53
|
+
return false if key_type.nil? || value_type.nil? || type_.types.size > 2
|
48
54
|
obj.each_pair do |key, val|
|
49
55
|
# Some objects (I'm looking at you Rack::Utils::HeaderHash) don't
|
50
|
-
# iterate over a [key, value] array, so we can't
|
56
|
+
# iterate over a [key, value] array, so we can't just use the type.recursively_valid?(v)
|
51
57
|
return false if !key_type.recursively_valid?(key) || !value_type.recursively_valid?(val)
|
52
58
|
end
|
53
59
|
true
|
@@ -65,10 +71,10 @@ module T::Types
|
|
65
71
|
# boundlessness, it does not express a type. For example `(nil...nil)` is not a T::Range[NilClass], its a range
|
66
72
|
# of unknown types (T::Range[T.untyped]).
|
67
73
|
# Similarly, `(nil...1)` is not a `T::Range[T.nilable(Integer)]`, it's a boundless range of Integer.
|
68
|
-
(obj.begin.nil? ||
|
74
|
+
(obj.begin.nil? || type.recursively_valid?(obj.begin)) && (obj.end.nil? || type.recursively_valid?(obj.end))
|
69
75
|
when Set
|
70
76
|
obj.each do |item|
|
71
|
-
return false unless
|
77
|
+
return false unless type.recursively_valid?(item)
|
72
78
|
end
|
73
79
|
|
74
80
|
true
|
@@ -90,7 +96,7 @@ module T::Types
|
|
90
96
|
# should be invariant because they are mutable and support
|
91
97
|
# both reading and writing. However, Sorbet treats *all*
|
92
98
|
# Enumerable subclasses as covariant for ease of adoption.
|
93
|
-
|
99
|
+
type.subtype_of?(other.type)
|
94
100
|
elsif other.class <= Simple
|
95
101
|
underlying_class <= other.raw_type
|
96
102
|
else
|
@@ -165,14 +171,14 @@ module T::Types
|
|
165
171
|
if T::Configuration::AT_LEAST_RUBY_2_7
|
166
172
|
Object.instance_method(:class).bind_call(obj)
|
167
173
|
else
|
168
|
-
Object.instance_method(:class).bind(obj).call
|
174
|
+
Object.instance_method(:class).bind(obj).call # rubocop:disable Performance/BindCall
|
169
175
|
end
|
170
176
|
end
|
171
177
|
end
|
172
178
|
|
173
179
|
class Untyped < TypedEnumerable
|
174
180
|
def initialize
|
175
|
-
super(T
|
181
|
+
super(T::Types::Untyped::Private::INSTANCE)
|
176
182
|
end
|
177
183
|
|
178
184
|
def valid?(obj)
|
@@ -3,15 +3,13 @@
|
|
3
3
|
|
4
4
|
module T::Types
|
5
5
|
class TypedEnumerator < TypedEnumerable
|
6
|
-
attr_reader :type
|
7
|
-
|
8
6
|
def underlying_class
|
9
7
|
Enumerator
|
10
8
|
end
|
11
9
|
|
12
10
|
# overrides Base
|
13
11
|
def name
|
14
|
-
"T::Enumerator[#{
|
12
|
+
"T::Enumerator[#{type.name}]"
|
15
13
|
end
|
16
14
|
|
17
15
|
# overrides Base
|
@@ -30,7 +28,7 @@ module T::Types
|
|
30
28
|
|
31
29
|
class Untyped < TypedEnumerator
|
32
30
|
def initialize
|
33
|
-
super(T
|
31
|
+
super(T::Types::Untyped::Private::INSTANCE)
|
34
32
|
end
|
35
33
|
|
36
34
|
def valid?(obj)
|
@@ -3,15 +3,13 @@
|
|
3
3
|
|
4
4
|
module T::Types
|
5
5
|
class TypedEnumeratorChain < TypedEnumerable
|
6
|
-
attr_reader :type
|
7
|
-
|
8
6
|
def underlying_class
|
9
7
|
Enumerator::Chain
|
10
8
|
end
|
11
9
|
|
12
10
|
# overrides Base
|
13
11
|
def name
|
14
|
-
"T::Enumerator::Chain[#{
|
12
|
+
"T::Enumerator::Chain[#{type.name}]"
|
15
13
|
end
|
16
14
|
|
17
15
|
# overrides Base
|
@@ -30,7 +28,7 @@ module T::Types
|
|
30
28
|
|
31
29
|
class Untyped < TypedEnumeratorChain
|
32
30
|
def initialize
|
33
|
-
super(T
|
31
|
+
super(T::Types::Untyped::Private::INSTANCE)
|
34
32
|
end
|
35
33
|
|
36
34
|
def valid?(obj)
|
@@ -3,15 +3,13 @@
|
|
3
3
|
|
4
4
|
module T::Types
|
5
5
|
class TypedEnumeratorLazy < TypedEnumerable
|
6
|
-
attr_reader :type
|
7
|
-
|
8
6
|
def underlying_class
|
9
7
|
Enumerator::Lazy
|
10
8
|
end
|
11
9
|
|
12
10
|
# overrides Base
|
13
11
|
def name
|
14
|
-
"T::Enumerator::Lazy[#{
|
12
|
+
"T::Enumerator::Lazy[#{type.name}]"
|
15
13
|
end
|
16
14
|
|
17
15
|
# overrides Base
|
@@ -30,7 +28,7 @@ module T::Types
|
|
30
28
|
|
31
29
|
class Untyped < TypedEnumeratorLazy
|
32
30
|
def initialize
|
33
|
-
super(T
|
31
|
+
super(T::Types::Untyped::Private::INSTANCE)
|
34
32
|
end
|
35
33
|
|
36
34
|
def valid?(obj)
|
@@ -3,22 +3,32 @@
|
|
3
3
|
|
4
4
|
module T::Types
|
5
5
|
class TypedHash < TypedEnumerable
|
6
|
-
# Technically we don't need these, but they are a nice api
|
7
|
-
attr_reader :keys, :values
|
8
|
-
|
9
6
|
def underlying_class
|
10
7
|
Hash
|
11
8
|
end
|
12
9
|
|
13
10
|
def initialize(keys:, values:)
|
14
|
-
@
|
15
|
-
@
|
16
|
-
|
11
|
+
@inner_keys = keys
|
12
|
+
@inner_values = values
|
13
|
+
end
|
14
|
+
|
15
|
+
# Technically we don't need this, but it is a nice api
|
16
|
+
def keys
|
17
|
+
@keys ||= T::Utils.coerce(@inner_keys)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Technically we don't need this, but it is a nice api
|
21
|
+
def values
|
22
|
+
@values ||= T::Utils.coerce(@inner_values)
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
@type ||= T::Utils.coerce([keys, values])
|
17
27
|
end
|
18
28
|
|
19
29
|
# overrides Base
|
20
30
|
def name
|
21
|
-
"T::Hash[#{
|
31
|
+
"T::Hash[#{keys.name}, #{values.name}]"
|
22
32
|
end
|
23
33
|
|
24
34
|
# overrides Base
|
@@ -3,15 +3,13 @@
|
|
3
3
|
|
4
4
|
module T::Types
|
5
5
|
class TypedRange < TypedEnumerable
|
6
|
-
attr_reader :type
|
7
|
-
|
8
6
|
def underlying_class
|
9
|
-
|
7
|
+
Range
|
10
8
|
end
|
11
9
|
|
12
10
|
# overrides Base
|
13
11
|
def name
|
14
|
-
"T::Range[#{
|
12
|
+
"T::Range[#{type.name}]"
|
15
13
|
end
|
16
14
|
|
17
15
|
# overrides Base
|
@@ -3,15 +3,13 @@
|
|
3
3
|
|
4
4
|
module T::Types
|
5
5
|
class TypedSet < TypedEnumerable
|
6
|
-
attr_reader :type
|
7
|
-
|
8
6
|
def underlying_class
|
9
|
-
|
7
|
+
Set
|
10
8
|
end
|
11
9
|
|
12
10
|
# overrides Base
|
13
11
|
def name
|
14
|
-
"T::Set[#{
|
12
|
+
"T::Set[#{type.name}]"
|
15
13
|
end
|
16
14
|
|
17
15
|
# overrides Base
|
@@ -39,7 +37,7 @@ module T::Types
|
|
39
37
|
|
40
38
|
class Untyped < TypedSet
|
41
39
|
def initialize
|
42
|
-
super(T
|
40
|
+
super(T::Types::Untyped::Private::INSTANCE)
|
43
41
|
end
|
44
42
|
|
45
43
|
def valid?(obj)
|
data/lib/types/types/union.rb
CHANGED
@@ -4,12 +4,14 @@
|
|
4
4
|
module T::Types
|
5
5
|
# Takes a list of types. Validates that an object matches at least one of the types.
|
6
6
|
class Union < Base
|
7
|
-
attr_reader :types
|
8
|
-
|
9
7
|
# Don't use Union.new directly, use `Private::Pool.union_of_types`
|
10
8
|
# inside sorbet-runtime and `T.any` elsewhere.
|
11
9
|
def initialize(types)
|
12
|
-
@
|
10
|
+
@inner_types = types
|
11
|
+
end
|
12
|
+
|
13
|
+
def types
|
14
|
+
@types ||= @inner_types.flat_map do |type|
|
13
15
|
type = T::Utils.coerce(type)
|
14
16
|
if type.is_a?(Union)
|
15
17
|
# Simplify nested unions (mostly so `name` returns a nicer value)
|
@@ -20,6 +22,11 @@ module T::Types
|
|
20
22
|
end.uniq
|
21
23
|
end
|
22
24
|
|
25
|
+
def build_type
|
26
|
+
types
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
23
30
|
# overrides Base
|
24
31
|
def name
|
25
32
|
# Use the attr_reader here so we can override it in SimplePairUnion
|
@@ -51,12 +58,12 @@ module T::Types
|
|
51
58
|
|
52
59
|
# overrides Base
|
53
60
|
def recursively_valid?(obj)
|
54
|
-
|
61
|
+
types.any? {|type| type.recursively_valid?(obj)}
|
55
62
|
end
|
56
63
|
|
57
64
|
# overrides Base
|
58
65
|
def valid?(obj)
|
59
|
-
|
66
|
+
types.any? {|type| type.valid?(obj)}
|
60
67
|
end
|
61
68
|
|
62
69
|
# overrides Base
|
data/lib/types/types/untyped.rb
CHANGED
data/lib/types/utils.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
module T::Utils
|
5
5
|
module Private
|
6
6
|
def self.coerce_and_check_module_types(val, check_val, check_module_type)
|
7
|
+
# rubocop:disable Style/CaseLikeIf
|
7
8
|
if val.is_a?(T::Types::Base)
|
8
9
|
if val.is_a?(T::Private::Types::TypeAlias)
|
9
10
|
val.aliased_type
|
@@ -31,6 +32,7 @@ module T::Utils
|
|
31
32
|
raise "Invalid value for type constraint. Must be an #{T::Types::Base}, a " \
|
32
33
|
"class/module, or an array. Got a `#{val.class}`."
|
33
34
|
end
|
35
|
+
# rubocop:enable Style/CaseLikeIf
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -79,8 +81,8 @@ module T::Utils
|
|
79
81
|
end
|
80
82
|
|
81
83
|
# Unwraps all the sigs.
|
82
|
-
def self.run_all_sig_blocks
|
83
|
-
T::Private::Methods.run_all_sig_blocks
|
84
|
+
def self.run_all_sig_blocks(force_type_init: true)
|
85
|
+
T::Private::Methods.run_all_sig_blocks(force_type_init: force_type_init)
|
84
86
|
end
|
85
87
|
|
86
88
|
# Return the underlying type for a type alias. Otherwise returns type.
|
@@ -153,7 +155,7 @@ module T::Utils
|
|
153
155
|
raise ArgumentError.new("#{enum.inspect} is not a T.deprecated_enum")
|
154
156
|
end
|
155
157
|
|
156
|
-
classes = enum.values.map(&:class).uniq
|
158
|
+
classes = T.unsafe(enum.values).map(&:class).uniq
|
157
159
|
if classes.empty?
|
158
160
|
T.untyped
|
159
161
|
elsif classes.length > 1
|
@@ -173,7 +175,7 @@ module T::Utils
|
|
173
175
|
def self.get_type_info(prop_type)
|
174
176
|
if prop_type.is_a?(T::Types::Union)
|
175
177
|
non_nilable_type = prop_type.unwrap_nilable
|
176
|
-
if non_nilable_type
|
178
|
+
if non_nilable_type.is_a?(T::Types::Simple)
|
177
179
|
non_nilable_type = non_nilable_type.raw_type
|
178
180
|
end
|
179
181
|
TypeInfo.new(true, non_nilable_type)
|
@@ -188,7 +190,7 @@ module T::Utils
|
|
188
190
|
def self.get_underlying_type(prop_type)
|
189
191
|
if prop_type.is_a?(T::Types::Union)
|
190
192
|
non_nilable_type = prop_type.unwrap_nilable
|
191
|
-
if non_nilable_type
|
193
|
+
if non_nilable_type.is_a?(T::Types::Simple)
|
192
194
|
non_nilable_type = non_nilable_type.raw_type
|
193
195
|
end
|
194
196
|
non_nilable_type || prop_type
|