sorbet-runtime 0.5.10782 → 0.5.10993
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 -0
- data/lib/types/_types.rb +13 -1
- data/lib/types/enum.rb +1 -1
- data/lib/types/private/abstract/declare.rb +10 -9
- data/lib/types/private/class_utils.rb +13 -6
- data/lib/types/private/methods/_methods.rb +27 -9
- data/lib/types/private/methods/call_validation.rb +1 -1
- data/lib/types/private/methods/call_validation_2_6.rb +68 -60
- data/lib/types/private/methods/call_validation_2_7.rb +68 -60
- data/lib/types/private/methods/decl_builder.rb +4 -2
- data/lib/types/private/methods/signature.rb +63 -38
- data/lib/types/private/methods/signature_validation.rb +55 -6
- data/lib/types/private/types/not_typed.rb +2 -0
- data/lib/types/props/decorator.rb +38 -35
- data/lib/types/props/has_lazily_specialized_methods.rb +1 -1
- data/lib/types/props/private/setter_factory.rb +1 -1
- data/lib/types/props/type_validation.rb +5 -2
- data/lib/types/struct.rb +2 -2
- data/lib/types/types/class_of.rb +11 -0
- data/lib/types/types/simple.rb +12 -1
- data/lib/types/types/type_parameter.rb +19 -0
- data/lib/types/types/typed_class.rb +85 -0
- data/lib/types/types/typed_enumerable.rb +2 -0
- metadata +5 -4
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module T::Types
|
5
|
+
class TypedClass < T::Types::Base
|
6
|
+
attr_reader :type
|
7
|
+
|
8
|
+
def initialize(type)
|
9
|
+
@type = T::Utils.coerce(type)
|
10
|
+
end
|
11
|
+
|
12
|
+
# overrides Base
|
13
|
+
def name
|
14
|
+
"T::Class[#{@type.name}]"
|
15
|
+
end
|
16
|
+
|
17
|
+
def underlying_class
|
18
|
+
Class
|
19
|
+
end
|
20
|
+
|
21
|
+
# overrides Base
|
22
|
+
def valid?(obj)
|
23
|
+
Class.===(obj)
|
24
|
+
end
|
25
|
+
|
26
|
+
# overrides Base
|
27
|
+
private def subtype_of_single?(type)
|
28
|
+
case type
|
29
|
+
when TypedClass
|
30
|
+
# treat like generics are erased
|
31
|
+
true
|
32
|
+
when Simple
|
33
|
+
Class <= type.raw_type
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module Private
|
40
|
+
module Pool
|
41
|
+
CACHE_FROZEN_OBJECTS =
|
42
|
+
begin
|
43
|
+
ObjectSpace::WeakMap.new[1] = 1
|
44
|
+
true # Ruby 2.7 and newer
|
45
|
+
rescue ArgumentError
|
46
|
+
false # Ruby 2.6 and older
|
47
|
+
end
|
48
|
+
|
49
|
+
@cache = ObjectSpace::WeakMap.new
|
50
|
+
|
51
|
+
def self.type_for_module(mod)
|
52
|
+
cached = @cache[mod]
|
53
|
+
return cached if cached
|
54
|
+
|
55
|
+
type = TypedClass.new(mod)
|
56
|
+
|
57
|
+
if CACHE_FROZEN_OBJECTS || (!mod.frozen? && !type.frozen?)
|
58
|
+
@cache[mod] = type
|
59
|
+
end
|
60
|
+
type
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Untyped < TypedClass
|
66
|
+
def initialize
|
67
|
+
super(T.untyped)
|
68
|
+
end
|
69
|
+
|
70
|
+
module Private
|
71
|
+
INSTANCE = Untyped.new.freeze
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Anything < TypedClass
|
76
|
+
def initialize
|
77
|
+
super(T.anything)
|
78
|
+
end
|
79
|
+
|
80
|
+
module Private
|
81
|
+
INSTANCE = Anything.new.freeze
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -91,6 +91,8 @@ module T::Types
|
|
91
91
|
# both reading and writing. However, Sorbet treats *all*
|
92
92
|
# Enumerable subclasses as covariant for ease of adoption.
|
93
93
|
@type.subtype_of?(other.type)
|
94
|
+
elsif other.class <= Simple
|
95
|
+
underlying_class <= other.raw_type
|
94
96
|
else
|
95
97
|
false
|
96
98
|
end
|
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.
|
4
|
+
version: 0.5.10993
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1
|
33
|
+
version: '2.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1
|
40
|
+
version: '2.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -233,6 +233,7 @@ files:
|
|
233
233
|
- lib/types/types/type_template.rb
|
234
234
|
- lib/types/types/type_variable.rb
|
235
235
|
- lib/types/types/typed_array.rb
|
236
|
+
- lib/types/types/typed_class.rb
|
236
237
|
- lib/types/types/typed_enumerable.rb
|
237
238
|
- lib/types/types/typed_enumerator.rb
|
238
239
|
- lib/types/types/typed_enumerator_chain.rb
|