rbi 0.3.12 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/rbi/printer.rb +2 -2
- data/lib/rbi/rbs/method_type_translator.rb +2 -1
- data/lib/rbi/rbs/type_translator.rb +176 -171
- data/lib/rbi/rewriters/add_sig_templates.rb +4 -4
- data/lib/rbi/rewriters/translate_rbs_sigs.rb +8 -2
- data/lib/rbi/version.rb +1 -1
- data/rbi/rbi.rbi +26 -14
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b16ad7a7871bcd9c82c0228320779a44e950d2e3e54acb5a2348815bb7a2db21
|
|
4
|
+
data.tar.gz: deecb7ad84e99bf420710f17d8d94627bdf6e82a25d54d46bb4d18c6dbdfc097
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 795d1adf5bbfdabb77cd3d47ab5e02b90f7f4d83f6dfa6e6531a1943e900b84ef863e750d7795ba109f6328025362f8dc31bfc0fef225938c552f121bba99f06
|
|
7
|
+
data.tar.gz: 6ef068e4c2e8bb7889a5c229fb59558b98bd041494bdc42213ad4e0cf1bdb00cf32e68f27204b665461d4dbfa7a3b6acc1f257295a62dc7b67f7c9bf4a3d0c5f
|
data/Gemfile
CHANGED
|
@@ -10,7 +10,7 @@ group(:development, :test) do
|
|
|
10
10
|
gem("minitest")
|
|
11
11
|
gem("minitest-reporters")
|
|
12
12
|
gem("rake", "~> 13.4")
|
|
13
|
-
gem("rubocop", "~> 1.
|
|
13
|
+
gem("rubocop", "~> 1.87", require: false)
|
|
14
14
|
gem("rubocop-shopify", require: false)
|
|
15
15
|
gem("rubocop-sorbet", require: false)
|
|
16
16
|
gem("sorbet", ">= 0.5.9204", require: false)
|
data/lib/rbi/printer.rb
CHANGED
|
@@ -748,7 +748,7 @@ module RBI
|
|
|
748
748
|
#: (Sig node) -> void
|
|
749
749
|
def print_sig_as_line(node)
|
|
750
750
|
printt
|
|
751
|
-
print("T::Sig::WithoutRuntime.") if node.without_runtime
|
|
751
|
+
print("::T::Sig::WithoutRuntime.") if node.without_runtime
|
|
752
752
|
print("sig")
|
|
753
753
|
print("(:final)") if node.is_final
|
|
754
754
|
print(" { ")
|
|
@@ -781,7 +781,7 @@ module RBI
|
|
|
781
781
|
has_modifiers = !modifiers.empty?
|
|
782
782
|
|
|
783
783
|
printt
|
|
784
|
-
print("T::Sig::WithoutRuntime.") if node.without_runtime
|
|
784
|
+
print("::T::Sig::WithoutRuntime.") if node.without_runtime
|
|
785
785
|
print("sig")
|
|
786
786
|
print("(:final)") if node.is_final
|
|
787
787
|
printn(" do")
|
|
@@ -22,6 +22,7 @@ module RBI
|
|
|
22
22
|
def initialize(method)
|
|
23
23
|
@method = method
|
|
24
24
|
@result = Sig.new #: Sig
|
|
25
|
+
@type_translator = TypeTranslator.new #: TypeTranslator
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
#: (::RBS::MethodType) -> void
|
|
@@ -113,7 +114,7 @@ module RBI
|
|
|
113
114
|
|
|
114
115
|
#: (untyped) -> Type
|
|
115
116
|
def translate_type(type)
|
|
116
|
-
|
|
117
|
+
@type_translator.translate(type)
|
|
117
118
|
end
|
|
118
119
|
end
|
|
119
120
|
end
|
|
@@ -4,196 +4,201 @@
|
|
|
4
4
|
module RBI
|
|
5
5
|
module RBS
|
|
6
6
|
class TypeTranslator
|
|
7
|
+
#: type rbs_type = ::RBS::Types::Alias
|
|
8
|
+
#| | ::RBS::Types::Bases::Any
|
|
9
|
+
#| | ::RBS::Types::Bases::Bool
|
|
10
|
+
#| | ::RBS::Types::Bases::Bottom
|
|
11
|
+
#| | ::RBS::Types::Bases::Class
|
|
12
|
+
#| | ::RBS::Types::Bases::Instance
|
|
13
|
+
#| | ::RBS::Types::Bases::Nil
|
|
14
|
+
#| | ::RBS::Types::Bases::Self
|
|
15
|
+
#| | ::RBS::Types::Bases::Top
|
|
16
|
+
#| | ::RBS::Types::Bases::Void
|
|
17
|
+
#| | ::RBS::Types::ClassSingleton
|
|
18
|
+
#| | ::RBS::Types::ClassInstance
|
|
19
|
+
#| | ::RBS::Types::Function
|
|
20
|
+
#| | ::RBS::Types::Interface
|
|
21
|
+
#| | ::RBS::Types::Intersection
|
|
22
|
+
#| | ::RBS::Types::Literal
|
|
23
|
+
#| | ::RBS::Types::Optional
|
|
24
|
+
#| | ::RBS::Types::Proc
|
|
25
|
+
#| | ::RBS::Types::Record
|
|
26
|
+
#| | ::RBS::Types::Tuple
|
|
27
|
+
#| | ::RBS::Types::Union
|
|
28
|
+
#| | ::RBS::Types::UntypedFunction
|
|
29
|
+
#| | ::RBS::Types::Variable
|
|
30
|
+
|
|
7
31
|
class << self
|
|
8
|
-
#: (
|
|
9
|
-
#| ::RBS::Types::Alias |
|
|
10
|
-
#| ::RBS::Types::Bases::Any |
|
|
11
|
-
#| ::RBS::Types::Bases::Bool |
|
|
12
|
-
#| ::RBS::Types::Bases::Bottom |
|
|
13
|
-
#| ::RBS::Types::Bases::Class |
|
|
14
|
-
#| ::RBS::Types::Bases::Instance |
|
|
15
|
-
#| ::RBS::Types::Bases::Nil |
|
|
16
|
-
#| ::RBS::Types::Bases::Self |
|
|
17
|
-
#| ::RBS::Types::Bases::Top |
|
|
18
|
-
#| ::RBS::Types::Bases::Void |
|
|
19
|
-
#| ::RBS::Types::ClassSingleton |
|
|
20
|
-
#| ::RBS::Types::ClassInstance |
|
|
21
|
-
#| ::RBS::Types::Function |
|
|
22
|
-
#| ::RBS::Types::Interface |
|
|
23
|
-
#| ::RBS::Types::Intersection |
|
|
24
|
-
#| ::RBS::Types::Literal |
|
|
25
|
-
#| ::RBS::Types::Optional |
|
|
26
|
-
#| ::RBS::Types::Proc |
|
|
27
|
-
#| ::RBS::Types::Record |
|
|
28
|
-
#| ::RBS::Types::Tuple |
|
|
29
|
-
#| ::RBS::Types::Union |
|
|
30
|
-
#| ::RBS::Types::UntypedFunction |
|
|
31
|
-
#| ::RBS::Types::Variable
|
|
32
|
-
#| ) -> Type
|
|
32
|
+
#: (rbs_type) -> Type
|
|
33
33
|
def translate(type)
|
|
34
|
-
|
|
35
|
-
when ::RBS::Types::Alias
|
|
36
|
-
translate_type_alias(type)
|
|
37
|
-
when ::RBS::Types::Bases::Any
|
|
38
|
-
Type.untyped
|
|
39
|
-
when ::RBS::Types::Bases::Bool
|
|
40
|
-
Type.boolean
|
|
41
|
-
when ::RBS::Types::Bases::Bottom
|
|
42
|
-
Type.noreturn
|
|
43
|
-
when ::RBS::Types::Bases::Class
|
|
44
|
-
Type.simple("Class")
|
|
45
|
-
when ::RBS::Types::Bases::Instance
|
|
46
|
-
Type.attached_class
|
|
47
|
-
when ::RBS::Types::Bases::Nil
|
|
48
|
-
Type.simple("NilClass")
|
|
49
|
-
when ::RBS::Types::Bases::Self
|
|
50
|
-
Type.self_type
|
|
51
|
-
when ::RBS::Types::Bases::Top
|
|
52
|
-
Type.anything
|
|
53
|
-
when ::RBS::Types::Bases::Void
|
|
54
|
-
Type.void
|
|
55
|
-
when ::RBS::Types::ClassSingleton
|
|
56
|
-
type_parameter = type.args.first ? translate(type.args.first) : nil
|
|
57
|
-
Type.class_of(Type.simple(type.name.to_s), type_parameter)
|
|
58
|
-
when ::RBS::Types::ClassInstance
|
|
59
|
-
translate_class_instance(type)
|
|
60
|
-
when ::RBS::Types::Function
|
|
61
|
-
translate_function(type)
|
|
62
|
-
when ::RBS::Types::Interface
|
|
63
|
-
# TODO: unsupported yet
|
|
64
|
-
# RBS interfaces (like _Foo) don't have a direct Sorbet equivalent
|
|
65
|
-
# and the names aren't valid Ruby identifiers
|
|
66
|
-
Type.untyped
|
|
67
|
-
when ::RBS::Types::Intersection
|
|
68
|
-
Type.all(*type.types.map { |t| translate(t) })
|
|
69
|
-
when ::RBS::Types::Literal
|
|
70
|
-
# Sorbet doesn't support literal types, so map to their base type
|
|
71
|
-
case type.literal
|
|
72
|
-
when nil then Type.simple("NilClass")
|
|
73
|
-
when true then Type.simple("TrueClass")
|
|
74
|
-
when false then Type.simple("FalseClass")
|
|
75
|
-
else
|
|
76
|
-
Type.simple(type.literal.class.to_s)
|
|
77
|
-
end
|
|
78
|
-
when ::RBS::Types::Optional
|
|
79
|
-
Type.nilable(translate(type.type))
|
|
80
|
-
when ::RBS::Types::Proc
|
|
81
|
-
proc = translate(type.type) #: as Type::Proc
|
|
82
|
-
proc.bind(translate(type.self_type)) if type.self_type
|
|
83
|
-
proc
|
|
84
|
-
when ::RBS::Types::Record
|
|
85
|
-
Type.shape(type.all_fields.to_h do |name, (value, required)|
|
|
86
|
-
translated = translate(value)
|
|
87
|
-
[name, required ? translated : Type.nilable(translated)]
|
|
88
|
-
end)
|
|
89
|
-
when ::RBS::Types::Tuple
|
|
90
|
-
Type.tuple(type.types.map { |t| translate(t) })
|
|
91
|
-
when ::RBS::Types::Union
|
|
92
|
-
Type.any(*type.types.map { |t| translate(t) })
|
|
93
|
-
when ::RBS::Types::UntypedFunction
|
|
94
|
-
Type.proc.params(arg0: Type.untyped).returns(Type.untyped)
|
|
95
|
-
when ::RBS::Types::Variable
|
|
96
|
-
Type.type_parameter(type.name)
|
|
97
|
-
else
|
|
98
|
-
type #: absurd
|
|
99
|
-
end
|
|
34
|
+
new.translate(type)
|
|
100
35
|
end
|
|
36
|
+
end
|
|
101
37
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
38
|
+
#: (rbs_type) -> Type
|
|
39
|
+
def translate(type)
|
|
40
|
+
case type
|
|
41
|
+
when ::RBS::Types::Alias
|
|
42
|
+
translate_type_alias(type)
|
|
43
|
+
when ::RBS::Types::Bases::Any
|
|
44
|
+
Type.untyped
|
|
45
|
+
when ::RBS::Types::Bases::Bool
|
|
46
|
+
Type.boolean
|
|
47
|
+
when ::RBS::Types::Bases::Bottom
|
|
48
|
+
Type.noreturn
|
|
49
|
+
when ::RBS::Types::Bases::Class
|
|
50
|
+
Type.simple("Class")
|
|
51
|
+
when ::RBS::Types::Bases::Instance
|
|
52
|
+
Type.attached_class
|
|
53
|
+
when ::RBS::Types::Bases::Nil
|
|
54
|
+
Type.simple("NilClass")
|
|
55
|
+
when ::RBS::Types::Bases::Self
|
|
56
|
+
Type.self_type
|
|
57
|
+
when ::RBS::Types::Bases::Top
|
|
58
|
+
Type.anything
|
|
59
|
+
when ::RBS::Types::Bases::Void
|
|
60
|
+
Type.void
|
|
61
|
+
when ::RBS::Types::ClassSingleton
|
|
62
|
+
type_parameter = type.args.first ? translate(type.args.first) : nil
|
|
63
|
+
Type.class_of(Type.simple(type.name.to_s), type_parameter)
|
|
64
|
+
when ::RBS::Types::ClassInstance
|
|
65
|
+
translate_class_instance(type)
|
|
66
|
+
when ::RBS::Types::Function
|
|
67
|
+
translate_function(type)
|
|
68
|
+
when ::RBS::Types::Interface
|
|
69
|
+
# TODO: unsupported yet
|
|
70
|
+
# RBS interfaces (like _Foo) don't have a direct Sorbet equivalent
|
|
71
|
+
# and the names aren't valid Ruby identifiers
|
|
72
|
+
Type.untyped
|
|
73
|
+
when ::RBS::Types::Intersection
|
|
74
|
+
Type.all(*type.types.map { |t| translate(t) })
|
|
75
|
+
when ::RBS::Types::Literal
|
|
76
|
+
# Sorbet doesn't support literal types, so map to their base type
|
|
77
|
+
case type.literal
|
|
78
|
+
when nil then Type.simple("NilClass")
|
|
79
|
+
when true then Type.simple("TrueClass")
|
|
80
|
+
when false then Type.simple("FalseClass")
|
|
81
|
+
else
|
|
82
|
+
Type.simple(type.literal.class.to_s)
|
|
83
|
+
end
|
|
84
|
+
when ::RBS::Types::Optional
|
|
85
|
+
Type.nilable(translate(type.type))
|
|
86
|
+
when ::RBS::Types::Proc
|
|
87
|
+
proc = translate(type.type) #: as Type::Proc
|
|
88
|
+
proc.bind(translate(type.self_type)) if type.self_type
|
|
89
|
+
proc
|
|
90
|
+
when ::RBS::Types::Record
|
|
91
|
+
Type.shape(type.all_fields.to_h do |name, (value, required)|
|
|
92
|
+
translated = translate(value)
|
|
93
|
+
[name, required ? translated : Type.nilable(translated)]
|
|
94
|
+
end)
|
|
95
|
+
when ::RBS::Types::Tuple
|
|
96
|
+
Type.tuple(type.types.map { |t| translate(t) })
|
|
97
|
+
when ::RBS::Types::Union
|
|
98
|
+
Type.any(*type.types.map { |t| translate(t) })
|
|
99
|
+
when ::RBS::Types::UntypedFunction
|
|
100
|
+
Type.proc.params(arg0: Type.untyped).returns(Type.untyped)
|
|
101
|
+
when ::RBS::Types::Variable
|
|
102
|
+
Type.type_parameter(type.name)
|
|
103
|
+
else
|
|
104
|
+
type #: absurd
|
|
114
105
|
end
|
|
106
|
+
end
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
#: (::RBS::Types::Alias) -> Type
|
|
111
|
+
def translate_type_alias(type)
|
|
112
|
+
name = ::RBS::TypeName.new(
|
|
113
|
+
namespace: type.name.namespace,
|
|
114
|
+
name: type.name.name.to_s.gsub(/(?:^|_)([a-z\d]*)/i) do |match|
|
|
115
|
+
match = match.delete_prefix("_")
|
|
116
|
+
!match.empty? ? match[0].upcase.concat(match[1..-1]) : +""
|
|
117
|
+
end,
|
|
118
|
+
)
|
|
119
|
+
Type.simple(name.to_s)
|
|
120
|
+
end
|
|
119
121
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
#: (::RBS::Types::ClassInstance) -> Type
|
|
123
|
+
def translate_class_instance(type)
|
|
124
|
+
return Type.simple(type.name.to_s) if type.args.empty?
|
|
123
125
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
type_name = translate_t_generic_type(type.name.to_s)
|
|
127
|
+
Type.generic(type_name, *type.args.map { |arg| translate(arg) })
|
|
128
|
+
end
|
|
127
129
|
|
|
128
|
-
|
|
130
|
+
#: (::RBS::Types::Function) -> Type
|
|
131
|
+
def translate_function(type)
|
|
132
|
+
proc = Type.proc
|
|
129
133
|
|
|
130
|
-
|
|
131
|
-
proc.proc_params[param.name || :"arg#{index}"] = translate(param.type)
|
|
132
|
-
index += 1
|
|
133
|
-
end
|
|
134
|
+
index = 0
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
type.required_positionals.each do |param|
|
|
137
|
+
proc.proc_params[param.name || :"arg#{index}"] = translate(param.type)
|
|
138
|
+
index += 1
|
|
139
|
+
end
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
end
|
|
141
|
+
type.optional_positionals.each do |param|
|
|
142
|
+
proc.proc_params[param.name || :"arg#{index}"] = translate(param.type)
|
|
143
|
+
index += 1
|
|
144
|
+
end
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
rest_positional = type.rest_positionals
|
|
147
|
+
if rest_positional
|
|
148
|
+
proc.proc_params[rest_positional.name || :"arg#{index}"] = translate(rest_positional.type)
|
|
149
|
+
index += 1
|
|
150
|
+
end
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
type.trailing_positionals.each do |param|
|
|
153
|
+
proc.proc_params[param.name || :"arg#{index}"] = translate(param.type)
|
|
154
|
+
index += 1
|
|
155
|
+
end
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
type.required_keywords.each do |name, param|
|
|
158
|
+
proc.proc_params[name.to_sym] = translate(param.type)
|
|
159
|
+
index += 1
|
|
160
|
+
end
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
end
|
|
162
|
+
type.optional_keywords.each do |name, param|
|
|
163
|
+
proc.proc_params[name.to_sym] = translate(param.type)
|
|
164
|
+
index += 1
|
|
165
|
+
end
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
rest_keyword = type.rest_keywords
|
|
168
|
+
if rest_keyword
|
|
169
|
+
proc.proc_params[rest_keyword.name || :"arg_#{index}"] = translate(rest_keyword.type)
|
|
170
|
+
index += 1
|
|
169
171
|
end
|
|
170
172
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
173
|
+
proc.returns(translate(type.return_type))
|
|
174
|
+
proc
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
#: (String type_name) -> String
|
|
178
|
+
def translate_t_generic_type(type_name)
|
|
179
|
+
case type_name.delete_prefix("::")
|
|
180
|
+
when "Array"
|
|
181
|
+
"::T::Array"
|
|
182
|
+
when "Class"
|
|
183
|
+
"::T::Class"
|
|
184
|
+
when "Enumerable"
|
|
185
|
+
"::T::Enumerable"
|
|
186
|
+
when "Enumerator"
|
|
187
|
+
"::T::Enumerator"
|
|
188
|
+
when "Enumerator::Chain"
|
|
189
|
+
"::T::Enumerator::Chain"
|
|
190
|
+
when "Enumerator::Lazy"
|
|
191
|
+
"::T::Enumerator::Lazy"
|
|
192
|
+
when "Hash"
|
|
193
|
+
"::T::Hash"
|
|
194
|
+
when "Module"
|
|
195
|
+
"::T::Module"
|
|
196
|
+
when "Set"
|
|
197
|
+
"::T::Set"
|
|
198
|
+
when "Range"
|
|
199
|
+
"::T::Range"
|
|
200
|
+
else
|
|
201
|
+
type_name
|
|
197
202
|
end
|
|
198
203
|
end
|
|
199
204
|
end
|
|
@@ -31,11 +31,11 @@ module RBI
|
|
|
31
31
|
return if attr.names.size > 1
|
|
32
32
|
|
|
33
33
|
params = []
|
|
34
|
-
params << SigParam.new(attr.names.first.to_s, "T.untyped") if attr.is_a?(AttrWriter)
|
|
34
|
+
params << SigParam.new(attr.names.first.to_s, "::T.untyped") if attr.is_a?(AttrWriter)
|
|
35
35
|
|
|
36
36
|
attr.sigs << Sig.new(
|
|
37
37
|
params: params,
|
|
38
|
-
return_type: "T.untyped",
|
|
38
|
+
return_type: "::T.untyped",
|
|
39
39
|
)
|
|
40
40
|
add_todo_comment(attr)
|
|
41
41
|
end
|
|
@@ -45,8 +45,8 @@ module RBI
|
|
|
45
45
|
return unless method.sigs.empty?
|
|
46
46
|
|
|
47
47
|
method.sigs << Sig.new(
|
|
48
|
-
params: method.params.map { |param| SigParam.new(param.name, "T.untyped") },
|
|
49
|
-
return_type: "T.untyped",
|
|
48
|
+
params: method.params.map { |param| SigParam.new(param.name, "::T.untyped") },
|
|
49
|
+
return_type: "::T.untyped",
|
|
50
50
|
)
|
|
51
51
|
add_todo_comment(method)
|
|
52
52
|
end
|
|
@@ -7,6 +7,12 @@ module RBI
|
|
|
7
7
|
class TranslateRBSSigs < Visitor
|
|
8
8
|
class Error < RBI::Error; end
|
|
9
9
|
|
|
10
|
+
#: -> void
|
|
11
|
+
def initialize
|
|
12
|
+
super
|
|
13
|
+
@type_translator = RBS::TypeTranslator.new #: RBS::TypeTranslator
|
|
14
|
+
end
|
|
15
|
+
|
|
10
16
|
# @override
|
|
11
17
|
#: (Node? node) -> void
|
|
12
18
|
def visit(node)
|
|
@@ -68,10 +74,10 @@ module RBI
|
|
|
68
74
|
end
|
|
69
75
|
|
|
70
76
|
name = node.names.first #: as !nil
|
|
71
|
-
sig.params << SigParam.new(name.to_s,
|
|
77
|
+
sig.params << SigParam.new(name.to_s, @type_translator.translate(attr_type))
|
|
72
78
|
end
|
|
73
79
|
|
|
74
|
-
sig.return_type =
|
|
80
|
+
sig.return_type = @type_translator.translate(attr_type)
|
|
75
81
|
sig
|
|
76
82
|
end
|
|
77
83
|
end
|
data/lib/rbi/version.rb
CHANGED
data/rbi/rbi.rbi
CHANGED
|
@@ -1418,6 +1418,27 @@ end
|
|
|
1418
1418
|
class RBI::RBS::MethodTypeTranslator::Error < ::RBI::Error; end
|
|
1419
1419
|
|
|
1420
1420
|
class RBI::RBS::TypeTranslator
|
|
1421
|
+
sig do
|
|
1422
|
+
params(
|
|
1423
|
+
type: T.any(::RBS::Types::Alias, ::RBS::Types::Bases::Any, ::RBS::Types::Bases::Bool, ::RBS::Types::Bases::Bottom, ::RBS::Types::Bases::Class, ::RBS::Types::Bases::Instance, ::RBS::Types::Bases::Nil, ::RBS::Types::Bases::Self, ::RBS::Types::Bases::Top, ::RBS::Types::Bases::Void, ::RBS::Types::ClassInstance, ::RBS::Types::ClassSingleton, ::RBS::Types::Function, ::RBS::Types::Interface, ::RBS::Types::Intersection, ::RBS::Types::Literal, ::RBS::Types::Optional, ::RBS::Types::Proc, ::RBS::Types::Record, ::RBS::Types::Tuple, ::RBS::Types::Union, ::RBS::Types::UntypedFunction, ::RBS::Types::Variable)
|
|
1424
|
+
).returns(::RBI::Type)
|
|
1425
|
+
end
|
|
1426
|
+
def translate(type); end
|
|
1427
|
+
|
|
1428
|
+
private
|
|
1429
|
+
|
|
1430
|
+
sig { params(type: ::RBS::Types::ClassInstance).returns(::RBI::Type) }
|
|
1431
|
+
def translate_class_instance(type); end
|
|
1432
|
+
|
|
1433
|
+
sig { params(type: ::RBS::Types::Function).returns(::RBI::Type) }
|
|
1434
|
+
def translate_function(type); end
|
|
1435
|
+
|
|
1436
|
+
sig { params(type_name: ::String).returns(::String) }
|
|
1437
|
+
def translate_t_generic_type(type_name); end
|
|
1438
|
+
|
|
1439
|
+
sig { params(type: ::RBS::Types::Alias).returns(::RBI::Type) }
|
|
1440
|
+
def translate_type_alias(type); end
|
|
1441
|
+
|
|
1421
1442
|
class << self
|
|
1422
1443
|
sig do
|
|
1423
1444
|
params(
|
|
@@ -1425,23 +1446,11 @@ class RBI::RBS::TypeTranslator
|
|
|
1425
1446
|
).returns(::RBI::Type)
|
|
1426
1447
|
end
|
|
1427
1448
|
def translate(type); end
|
|
1428
|
-
|
|
1429
|
-
private
|
|
1430
|
-
|
|
1431
|
-
sig { params(type: ::RBS::Types::ClassInstance).returns(::RBI::Type) }
|
|
1432
|
-
def translate_class_instance(type); end
|
|
1433
|
-
|
|
1434
|
-
sig { params(type: ::RBS::Types::Function).returns(::RBI::Type) }
|
|
1435
|
-
def translate_function(type); end
|
|
1436
|
-
|
|
1437
|
-
sig { params(type_name: ::String).returns(::String) }
|
|
1438
|
-
def translate_t_generic_type(type_name); end
|
|
1439
|
-
|
|
1440
|
-
sig { params(type: ::RBS::Types::Alias).returns(::RBI::Type) }
|
|
1441
|
-
def translate_type_alias(type); end
|
|
1442
1449
|
end
|
|
1443
1450
|
end
|
|
1444
1451
|
|
|
1452
|
+
RBI::RBS::TypeTranslator::RbsType = T.type_alias { T.any(::RBS::Types::Alias, ::RBS::Types::Bases::Any, ::RBS::Types::Bases::Bool, ::RBS::Types::Bases::Bottom, ::RBS::Types::Bases::Class, ::RBS::Types::Bases::Instance, ::RBS::Types::Bases::Nil, ::RBS::Types::Bases::Self, ::RBS::Types::Bases::Top, ::RBS::Types::Bases::Void, ::RBS::Types::ClassInstance, ::RBS::Types::ClassSingleton, ::RBS::Types::Function, ::RBS::Types::Interface, ::RBS::Types::Intersection, ::RBS::Types::Literal, ::RBS::Types::Optional, ::RBS::Types::Proc, ::RBS::Types::Record, ::RBS::Types::Tuple, ::RBS::Types::Union, ::RBS::Types::UntypedFunction, ::RBS::Types::Variable) }
|
|
1453
|
+
|
|
1445
1454
|
class RBI::RBSComment < ::RBI::Comment
|
|
1446
1455
|
sig { params(other: ::Object).returns(T::Boolean) }
|
|
1447
1456
|
def ==(other); end
|
|
@@ -2022,6 +2031,9 @@ class RBI::Rewriters::SortNodes < ::RBI::Visitor
|
|
|
2022
2031
|
end
|
|
2023
2032
|
|
|
2024
2033
|
class RBI::Rewriters::TranslateRBSSigs < ::RBI::Visitor
|
|
2034
|
+
sig { void }
|
|
2035
|
+
def initialize; end
|
|
2036
|
+
|
|
2025
2037
|
sig { override.params(node: T.nilable(::RBI::Node)).void }
|
|
2026
2038
|
def visit(node); end
|
|
2027
2039
|
|