rbs 4.0.0.dev.5 → 4.0.1.dev.1
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/.clang-format +1 -0
- data/.github/workflows/c-check.yml +8 -4
- data/.github/workflows/comments.yml +3 -1
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +10 -0
- data/.github/workflows/rust.yml +95 -0
- data/CHANGELOG.md +323 -0
- data/Rakefile +12 -29
- data/Steepfile +1 -0
- data/config.yml +393 -37
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +52 -40
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +5 -5
- data/core/enumerable.rbs +96 -91
- data/core/enumerator.rbs +4 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +36 -36
- data/core/file.rbs +186 -113
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +41 -32
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -28
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +120 -135
- data/core/kernel.rbs +189 -139
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -6
- data/core/module.rbs +146 -85
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +35 -32
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -33
- data/core/process.rbs +219 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +4 -3
- data/core/range.rbs +52 -47
- data/core/rational.rbs +5 -5
- data/core/rbs/unnamed/argf.rbs +58 -51
- data/core/rbs/unnamed/env_class.rbs +18 -13
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +7 -5
- data/core/regexp.rbs +236 -197
- data/core/ruby.rbs +1 -1
- data/core/ruby_vm.rbs +32 -30
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +1 -1
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +5 -3
- data/core/set.rbs +17 -16
- data/core/signal.rbs +2 -2
- data/core/string.rbs +311 -292
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -34
- data/core/time.rbs +47 -42
- data/core/trace_point.rbs +34 -31
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +10 -10
- data/core/warning.rbs +7 -7
- data/docs/collection.md +1 -1
- data/docs/config.md +171 -0
- data/docs/inline.md +110 -4
- data/docs/syntax.md +13 -12
- data/ext/rbs_extension/ast_translation.c +489 -135
- data/ext/rbs_extension/class_constants.c +8 -0
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/legacy_location.c +28 -51
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +12 -20
- data/include/rbs/ast.h +423 -195
- data/include/rbs/lexer.h +2 -2
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +2 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/ruby/annotations.rb +157 -4
- data/lib/rbs/ast/ruby/members.rb +374 -22
- data/lib/rbs/cli/validate.rb +5 -60
- data/lib/rbs/collection/config/lockfile_generator.rb +6 -2
- data/lib/rbs/definition_builder.rb +60 -27
- data/lib/rbs/errors.rb +0 -11
- data/lib/rbs/inline_parser.rb +1 -1
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +1 -26
- data/lib/rbs/prototype/rbi.rb +1 -20
- data/lib/rbs/test/type_check.rb +3 -0
- data/lib/rbs/types.rb +62 -52
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +0 -1
- data/rbs.gemspec +1 -1
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/sig/ast/ruby/annotations.rbs +191 -4
- data/sig/ast/ruby/members.rbs +21 -1
- data/sig/cli/validate.rbs +1 -6
- data/sig/definition_builder.rbs +2 -0
- data/sig/errors.rbs +0 -8
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +17 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/types.rbs +10 -11
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +339 -161
- data/src/lexstate.c +1 -1
- data/src/location.c +7 -47
- data/src/parser.c +674 -480
- data/src/util/rbs_constant_pool.c +0 -4
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
- data/stdlib/cgi-escape/0/escape.rbs +4 -4
- data/stdlib/coverage/0/coverage.rbs +4 -3
- data/stdlib/date/0/date.rbs +33 -28
- data/stdlib/date/0/date_time.rbs +24 -23
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +138 -125
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +135 -108
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +159 -134
- data/stdlib/objspace/0/objspace.rbs +8 -7
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +36 -35
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +18 -14
- data/stdlib/pathname/0/pathname.rbs +2 -2
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +61 -8
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +2 -2
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/securerandom.rbs +1 -1
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +10 -9
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +1 -1
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +55 -54
- data/stdlib/strscan/0/string_scanner.rbs +46 -44
- data/stdlib/tempfile/0/tempfile.rbs +24 -20
- data/stdlib/time/0/time.rbs +7 -5
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +26 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -5
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +4 -4
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- metadata +23 -5
- data/.github/workflows/valgrind.yml +0 -42
data/lib/rbs/ast/ruby/members.rb
CHANGED
|
@@ -17,19 +17,271 @@ module RBS
|
|
|
17
17
|
class MethodTypeAnnotation
|
|
18
18
|
class DocStyle
|
|
19
19
|
attr_accessor :return_type_annotation
|
|
20
|
+
attr_reader :required_positionals
|
|
21
|
+
attr_reader :optional_positionals
|
|
22
|
+
attr_accessor :rest_positionals
|
|
23
|
+
attr_reader :trailing_positionals
|
|
24
|
+
attr_reader :required_keywords
|
|
25
|
+
attr_reader :optional_keywords
|
|
26
|
+
attr_accessor :rest_keywords
|
|
27
|
+
attr_accessor :block
|
|
20
28
|
|
|
21
29
|
def initialize
|
|
22
30
|
@return_type_annotation = nil
|
|
31
|
+
@required_positionals = []
|
|
32
|
+
@optional_positionals = []
|
|
33
|
+
@rest_positionals = nil
|
|
34
|
+
@trailing_positionals = []
|
|
35
|
+
@required_keywords = {}
|
|
36
|
+
@optional_keywords = {}
|
|
37
|
+
@rest_keywords = nil
|
|
38
|
+
@block = nil
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.build(param_type_annotations, return_type_annotation, node)
|
|
42
|
+
doc = DocStyle.new
|
|
43
|
+
doc.return_type_annotation = return_type_annotation
|
|
44
|
+
|
|
45
|
+
splat_annotation = nil #: Annotations::SplatParamTypeAnnotation?
|
|
46
|
+
double_splat_annotation = nil #: Annotations::DoubleSplatParamTypeAnnotation?
|
|
47
|
+
block_annotation = nil #: Annotations::BlockParamTypeAnnotation?
|
|
48
|
+
param_annotations = {} #: Hash[Symbol, Annotations::ParamTypeAnnotation]
|
|
49
|
+
unused = [] #: Array[Annotations::ParamTypeAnnotation | Annotations::SplatParamTypeAnnotation | Annotations::DoubleSplatParamTypeAnnotation | Annotations::BlockParamTypeAnnotation]
|
|
50
|
+
|
|
51
|
+
param_type_annotations.each do |annot|
|
|
52
|
+
case annot
|
|
53
|
+
when Annotations::SplatParamTypeAnnotation
|
|
54
|
+
if splat_annotation
|
|
55
|
+
unused << annot
|
|
56
|
+
else
|
|
57
|
+
splat_annotation = annot
|
|
58
|
+
end
|
|
59
|
+
when Annotations::DoubleSplatParamTypeAnnotation
|
|
60
|
+
if double_splat_annotation
|
|
61
|
+
unused << annot
|
|
62
|
+
else
|
|
63
|
+
double_splat_annotation = annot
|
|
64
|
+
end
|
|
65
|
+
when Annotations::BlockParamTypeAnnotation
|
|
66
|
+
if block_annotation
|
|
67
|
+
unused << annot
|
|
68
|
+
else
|
|
69
|
+
block_annotation = annot
|
|
70
|
+
end
|
|
71
|
+
when Annotations::ParamTypeAnnotation
|
|
72
|
+
name = annot.name_location.source.to_sym
|
|
73
|
+
if param_annotations.key?(name)
|
|
74
|
+
unused << annot
|
|
75
|
+
else
|
|
76
|
+
param_annotations[name] = annot
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
if node.parameters
|
|
82
|
+
params = node.parameters #: Prism::ParametersNode
|
|
83
|
+
|
|
84
|
+
params.requireds.each do |param|
|
|
85
|
+
if param.is_a?(Prism::RequiredParameterNode)
|
|
86
|
+
annotation = param_annotations.delete(param.name)
|
|
87
|
+
if annotation
|
|
88
|
+
doc.required_positionals << annotation
|
|
89
|
+
else
|
|
90
|
+
doc.required_positionals << param.name
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
params.optionals.each do |param|
|
|
96
|
+
if param.is_a?(Prism::OptionalParameterNode)
|
|
97
|
+
annotation = param_annotations.delete(param.name)
|
|
98
|
+
if annotation
|
|
99
|
+
doc.optional_positionals << annotation
|
|
100
|
+
else
|
|
101
|
+
doc.optional_positionals << param.name
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
if (rest = params.rest) && rest.is_a?(Prism::RestParameterNode)
|
|
107
|
+
if splat_annotation && (splat_annotation.name_location.nil? || rest.name.nil? || splat_annotation.name_location.source.to_sym == rest.name)
|
|
108
|
+
doc.rest_positionals = splat_annotation
|
|
109
|
+
splat_annotation = nil
|
|
110
|
+
else
|
|
111
|
+
doc.rest_positionals = rest.name || true
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
params.posts.each do |param|
|
|
116
|
+
if param.is_a?(Prism::RequiredParameterNode)
|
|
117
|
+
annotation = param_annotations.delete(param.name)
|
|
118
|
+
if annotation
|
|
119
|
+
doc.trailing_positionals << annotation
|
|
120
|
+
else
|
|
121
|
+
doc.trailing_positionals << param.name
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
params.keywords.each do |param|
|
|
127
|
+
case param
|
|
128
|
+
when Prism::RequiredKeywordParameterNode
|
|
129
|
+
annotation = param_annotations.delete(param.name)
|
|
130
|
+
if annotation
|
|
131
|
+
doc.required_keywords[param.name] = annotation
|
|
132
|
+
else
|
|
133
|
+
doc.required_keywords[param.name] = param.name
|
|
134
|
+
end
|
|
135
|
+
when Prism::OptionalKeywordParameterNode
|
|
136
|
+
annotation = param_annotations.delete(param.name)
|
|
137
|
+
if annotation
|
|
138
|
+
doc.optional_keywords[param.name] = annotation
|
|
139
|
+
else
|
|
140
|
+
doc.optional_keywords[param.name] = param.name
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
if (kw_rest = params.keyword_rest) && kw_rest.is_a?(Prism::KeywordRestParameterNode)
|
|
146
|
+
if double_splat_annotation && (double_splat_annotation.name_location.nil? || kw_rest.name.nil? || double_splat_annotation.name_location.source.to_sym == kw_rest.name)
|
|
147
|
+
doc.rest_keywords = double_splat_annotation
|
|
148
|
+
double_splat_annotation = nil
|
|
149
|
+
else
|
|
150
|
+
doc.rest_keywords = kw_rest.name || true
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
if (blk = params.block) && blk.is_a?(Prism::BlockParameterNode)
|
|
155
|
+
if block_annotation && (block_annotation.name_location.nil? || blk.name.nil? || block_annotation.name == blk.name)
|
|
156
|
+
doc.block = block_annotation
|
|
157
|
+
block_annotation = nil
|
|
158
|
+
else
|
|
159
|
+
doc.block = blk.name || true
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
if block_annotation
|
|
165
|
+
if node.parameters&.block
|
|
166
|
+
# Block parameter exists but name didn't match -- treat as unused
|
|
167
|
+
else
|
|
168
|
+
doc.block = block_annotation
|
|
169
|
+
block_annotation = nil
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
unused.concat(param_annotations.values)
|
|
174
|
+
unused << splat_annotation if splat_annotation
|
|
175
|
+
unused << double_splat_annotation if double_splat_annotation
|
|
176
|
+
unused << block_annotation if block_annotation
|
|
177
|
+
|
|
178
|
+
[doc, unused]
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def all_param_annotations
|
|
182
|
+
annotations = [] #: Array[param_type_annotation | Symbol | true | nil]
|
|
183
|
+
|
|
184
|
+
required_positionals.each { |a| annotations << a }
|
|
185
|
+
optional_positionals.each { |a| annotations << a }
|
|
186
|
+
annotations << rest_positionals
|
|
187
|
+
trailing_positionals.each { |a| annotations << a }
|
|
188
|
+
required_keywords.each_value { |a| annotations << a }
|
|
189
|
+
optional_keywords.each_value { |a| annotations << a }
|
|
190
|
+
annotations << rest_keywords
|
|
191
|
+
annotations << block
|
|
192
|
+
|
|
193
|
+
annotations
|
|
23
194
|
end
|
|
24
195
|
|
|
25
196
|
def map_type_name(&block)
|
|
26
197
|
DocStyle.new.tap do |new|
|
|
27
198
|
new.return_type_annotation = return_type_annotation&.map_type_name(&block)
|
|
199
|
+
new.required_positionals.replace(
|
|
200
|
+
required_positionals.map do |a|
|
|
201
|
+
case a
|
|
202
|
+
when Annotations::ParamTypeAnnotation
|
|
203
|
+
a.map_type_name(&block)
|
|
204
|
+
else
|
|
205
|
+
a
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
)
|
|
209
|
+
new.optional_positionals.replace(
|
|
210
|
+
optional_positionals.map do |a|
|
|
211
|
+
case a
|
|
212
|
+
when Annotations::ParamTypeAnnotation
|
|
213
|
+
a.map_type_name(&block)
|
|
214
|
+
else
|
|
215
|
+
a
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
)
|
|
219
|
+
new.rest_positionals =
|
|
220
|
+
case rest_positionals
|
|
221
|
+
when Annotations::SplatParamTypeAnnotation
|
|
222
|
+
rest_positionals.map_type_name(&block)
|
|
223
|
+
else
|
|
224
|
+
rest_positionals
|
|
225
|
+
end
|
|
226
|
+
new.trailing_positionals.replace(
|
|
227
|
+
trailing_positionals.map do |a|
|
|
228
|
+
case a
|
|
229
|
+
when Annotations::ParamTypeAnnotation
|
|
230
|
+
a.map_type_name(&block)
|
|
231
|
+
else
|
|
232
|
+
a
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
)
|
|
236
|
+
new.required_keywords.replace(
|
|
237
|
+
required_keywords.transform_values do |a|
|
|
238
|
+
case a
|
|
239
|
+
when Annotations::ParamTypeAnnotation
|
|
240
|
+
a.map_type_name(&block)
|
|
241
|
+
else
|
|
242
|
+
a
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
)
|
|
246
|
+
new.optional_keywords.replace(
|
|
247
|
+
optional_keywords.transform_values do |a|
|
|
248
|
+
case a
|
|
249
|
+
when Annotations::ParamTypeAnnotation
|
|
250
|
+
a.map_type_name(&block)
|
|
251
|
+
else
|
|
252
|
+
a
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
)
|
|
256
|
+
new.rest_keywords =
|
|
257
|
+
case rest_keywords
|
|
258
|
+
when Annotations::DoubleSplatParamTypeAnnotation
|
|
259
|
+
rest_keywords.map_type_name(&block)
|
|
260
|
+
else
|
|
261
|
+
rest_keywords
|
|
262
|
+
end
|
|
263
|
+
new.block =
|
|
264
|
+
case self.block
|
|
265
|
+
when Annotations::BlockParamTypeAnnotation
|
|
266
|
+
self.block.map_type_name(&block)
|
|
267
|
+
else
|
|
268
|
+
self.block
|
|
269
|
+
end
|
|
28
270
|
end #: self
|
|
29
271
|
end
|
|
30
272
|
|
|
31
273
|
def type_fingerprint
|
|
32
|
-
|
|
274
|
+
[
|
|
275
|
+
return_type_annotation&.type_fingerprint,
|
|
276
|
+
all_param_annotations.map do |param|
|
|
277
|
+
case param
|
|
278
|
+
when Annotations::Base
|
|
279
|
+
param.type_fingerprint
|
|
280
|
+
else
|
|
281
|
+
param
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
]
|
|
33
285
|
end
|
|
34
286
|
|
|
35
287
|
def method_type
|
|
@@ -43,21 +295,104 @@ module RBS
|
|
|
43
295
|
Types::Bases::Any.new(location: nil)
|
|
44
296
|
end
|
|
45
297
|
|
|
298
|
+
any = -> { Types::Bases::Any.new(location: nil) }
|
|
299
|
+
|
|
300
|
+
req_pos = required_positionals.map do |a|
|
|
301
|
+
case a
|
|
302
|
+
when Annotations::ParamTypeAnnotation
|
|
303
|
+
Types::Function::Param.new(type: a.param_type, name: a.name_location.source.to_sym)
|
|
304
|
+
else
|
|
305
|
+
Types::Function::Param.new(type: any.call, name: a)
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
opt_pos = optional_positionals.map do |a|
|
|
309
|
+
case a
|
|
310
|
+
when Annotations::ParamTypeAnnotation
|
|
311
|
+
Types::Function::Param.new(type: a.param_type, name: a.name_location.source.to_sym)
|
|
312
|
+
else
|
|
313
|
+
Types::Function::Param.new(type: any.call, name: a)
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
rest_pos =
|
|
317
|
+
case rest_positionals
|
|
318
|
+
when Annotations::SplatParamTypeAnnotation
|
|
319
|
+
Types::Function::Param.new(type: rest_positionals.param_type, name: rest_positionals.name_location&.source&.to_sym)
|
|
320
|
+
when Symbol
|
|
321
|
+
Types::Function::Param.new(type: any.call, name: rest_positionals)
|
|
322
|
+
when true
|
|
323
|
+
Types::Function::Param.new(type: any.call, name: nil)
|
|
324
|
+
else
|
|
325
|
+
nil
|
|
326
|
+
end
|
|
327
|
+
trail_pos = trailing_positionals.map do |a|
|
|
328
|
+
case a
|
|
329
|
+
when Annotations::ParamTypeAnnotation
|
|
330
|
+
Types::Function::Param.new(type: a.param_type, name: a.name_location.source.to_sym)
|
|
331
|
+
else
|
|
332
|
+
Types::Function::Param.new(type: any.call, name: a)
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
req_kw = required_keywords.transform_values do |a|
|
|
337
|
+
case a
|
|
338
|
+
when Annotations::ParamTypeAnnotation
|
|
339
|
+
Types::Function::Param.new(type: a.param_type, name: nil)
|
|
340
|
+
else
|
|
341
|
+
Types::Function::Param.new(type: any.call, name: nil)
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
opt_kw = optional_keywords.transform_values do |a|
|
|
345
|
+
case a
|
|
346
|
+
when Annotations::ParamTypeAnnotation
|
|
347
|
+
Types::Function::Param.new(type: a.param_type, name: nil)
|
|
348
|
+
else
|
|
349
|
+
Types::Function::Param.new(type: any.call, name: nil)
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
rest_kw =
|
|
354
|
+
case rest_keywords
|
|
355
|
+
when Annotations::DoubleSplatParamTypeAnnotation
|
|
356
|
+
Types::Function::Param.new(type: rest_keywords.param_type, name: rest_keywords.name_location&.source&.to_sym)
|
|
357
|
+
when Symbol
|
|
358
|
+
Types::Function::Param.new(type: any.call, name: rest_keywords)
|
|
359
|
+
when true
|
|
360
|
+
Types::Function::Param.new(type: any.call, name: nil)
|
|
361
|
+
else
|
|
362
|
+
nil
|
|
363
|
+
end
|
|
364
|
+
|
|
46
365
|
type = Types::Function.new(
|
|
47
|
-
required_positionals:
|
|
48
|
-
optional_positionals:
|
|
49
|
-
rest_positionals:
|
|
50
|
-
trailing_positionals:
|
|
51
|
-
required_keywords:
|
|
52
|
-
optional_keywords:
|
|
53
|
-
rest_keywords:
|
|
366
|
+
required_positionals: req_pos,
|
|
367
|
+
optional_positionals: opt_pos,
|
|
368
|
+
rest_positionals: rest_pos,
|
|
369
|
+
trailing_positionals: trail_pos,
|
|
370
|
+
required_keywords: req_kw,
|
|
371
|
+
optional_keywords: opt_kw,
|
|
372
|
+
rest_keywords: rest_kw,
|
|
54
373
|
return_type: return_type
|
|
55
374
|
)
|
|
56
375
|
|
|
376
|
+
method_block =
|
|
377
|
+
case self.block
|
|
378
|
+
when Annotations::BlockParamTypeAnnotation
|
|
379
|
+
Types::Block.new(
|
|
380
|
+
type: self.block.type,
|
|
381
|
+
required: self.block.required?
|
|
382
|
+
)
|
|
383
|
+
when Symbol, true
|
|
384
|
+
Types::Block.new(
|
|
385
|
+
type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)),
|
|
386
|
+
required: false
|
|
387
|
+
)
|
|
388
|
+
else
|
|
389
|
+
nil
|
|
390
|
+
end
|
|
391
|
+
|
|
57
392
|
MethodType.new(
|
|
58
393
|
type_params: [],
|
|
59
394
|
type: type,
|
|
60
|
-
block:
|
|
395
|
+
block: method_block,
|
|
61
396
|
location: nil
|
|
62
397
|
)
|
|
63
398
|
end
|
|
@@ -82,17 +417,18 @@ module RBS
|
|
|
82
417
|
MethodTypeAnnotation.new(type_annotations: updated_annots) #: self
|
|
83
418
|
end
|
|
84
419
|
|
|
85
|
-
def self.build(leading_block, trailing_block, variables)
|
|
420
|
+
def self.build(leading_block, trailing_block, variables, node)
|
|
86
421
|
unused_annotations = [] #: Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError]
|
|
87
422
|
unused_trailing_annotation = nil #: Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
|
|
88
423
|
|
|
89
424
|
type_annotations = nil #: type_annotations
|
|
425
|
+
return_annotation = nil #: Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil
|
|
426
|
+
param_annotations = [] #: Array[Annotations::ParamTypeAnnotation | Annotations::SplatParamTypeAnnotation | Annotations::DoubleSplatParamTypeAnnotation | Annotations::BlockParamTypeAnnotation]
|
|
90
427
|
|
|
91
428
|
if trailing_block
|
|
92
429
|
case annotation = trailing_block.trailing_annotation(variables)
|
|
93
430
|
when Annotations::NodeTypeAssertion
|
|
94
|
-
|
|
95
|
-
type_annotations.return_type_annotation = annotation
|
|
431
|
+
return_annotation = annotation
|
|
96
432
|
else
|
|
97
433
|
unused_trailing_annotation = annotation
|
|
98
434
|
end
|
|
@@ -116,25 +452,30 @@ module RBS
|
|
|
116
452
|
end
|
|
117
453
|
when Annotations::ReturnTypeAnnotation
|
|
118
454
|
unless type_annotations
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if type_annotations.is_a?(DocStyle)
|
|
123
|
-
unless type_annotations.return_type_annotation
|
|
124
|
-
type_annotations.return_type_annotation = paragraph
|
|
455
|
+
unless return_annotation
|
|
456
|
+
return_annotation = paragraph
|
|
125
457
|
next
|
|
126
458
|
end
|
|
127
459
|
end
|
|
460
|
+
when Annotations::ParamTypeAnnotation, Annotations::SplatParamTypeAnnotation, Annotations::DoubleSplatParamTypeAnnotation, Annotations::BlockParamTypeAnnotation
|
|
461
|
+
unless type_annotations
|
|
462
|
+
param_annotations << paragraph
|
|
463
|
+
next
|
|
464
|
+
end
|
|
128
465
|
end
|
|
129
466
|
|
|
130
467
|
unused_annotations << paragraph
|
|
131
468
|
end
|
|
132
469
|
end
|
|
133
470
|
|
|
471
|
+
if !type_annotations && (return_annotation || !param_annotations.empty?)
|
|
472
|
+
doc_style, unused_params = DocStyle.build(param_annotations, return_annotation, node)
|
|
473
|
+
type_annotations = doc_style
|
|
474
|
+
unused_annotations.concat(unused_params)
|
|
475
|
+
end
|
|
476
|
+
|
|
134
477
|
[
|
|
135
|
-
MethodTypeAnnotation.new(
|
|
136
|
-
type_annotations: type_annotations
|
|
137
|
-
),
|
|
478
|
+
MethodTypeAnnotation.new(type_annotations: type_annotations),
|
|
138
479
|
unused_annotations,
|
|
139
480
|
unused_trailing_annotation
|
|
140
481
|
]
|
|
@@ -180,6 +521,17 @@ module RBS
|
|
|
180
521
|
end
|
|
181
522
|
end
|
|
182
523
|
|
|
524
|
+
def overloading?
|
|
525
|
+
case type_annotations
|
|
526
|
+
when Array
|
|
527
|
+
type_annotations.any? do |annotation|
|
|
528
|
+
annotation.is_a?(Annotations::MethodTypesAnnotation) && annotation.dot3_location
|
|
529
|
+
end
|
|
530
|
+
else
|
|
531
|
+
false
|
|
532
|
+
end
|
|
533
|
+
end
|
|
534
|
+
|
|
183
535
|
def type_fingerprint
|
|
184
536
|
case type_annotations
|
|
185
537
|
when DocStyle
|
|
@@ -217,7 +569,7 @@ module RBS
|
|
|
217
569
|
end
|
|
218
570
|
|
|
219
571
|
def overloading?
|
|
220
|
-
|
|
572
|
+
method_type.overloading?
|
|
221
573
|
end
|
|
222
574
|
|
|
223
575
|
def annotations
|
data/lib/rbs/cli/validate.rb
CHANGED
|
@@ -4,20 +4,13 @@ module RBS
|
|
|
4
4
|
class CLI
|
|
5
5
|
class Validate
|
|
6
6
|
class Errors
|
|
7
|
-
def initialize(limit
|
|
7
|
+
def initialize(limit:)
|
|
8
8
|
@limit = limit
|
|
9
|
-
@exit_error = exit_error
|
|
10
9
|
@errors = []
|
|
11
|
-
@has_syntax_error = false
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
def add(error)
|
|
15
|
-
|
|
16
|
-
RBS.logger.warn(build_message(error))
|
|
17
|
-
@has_syntax_error = true
|
|
18
|
-
else
|
|
19
|
-
@errors << error
|
|
20
|
-
end
|
|
13
|
+
@errors << error
|
|
21
14
|
finish if @limit == 1
|
|
22
15
|
end
|
|
23
16
|
|
|
@@ -30,13 +23,7 @@ module RBS
|
|
|
30
23
|
end
|
|
31
24
|
|
|
32
25
|
def finish
|
|
33
|
-
|
|
34
|
-
if @exit_error && @has_syntax_error
|
|
35
|
-
throw @tag, 1
|
|
36
|
-
else
|
|
37
|
-
# success
|
|
38
|
-
end
|
|
39
|
-
else
|
|
26
|
+
unless @errors.empty?
|
|
40
27
|
@errors.each do |error|
|
|
41
28
|
RBS.logger.error(build_message(error))
|
|
42
29
|
end
|
|
@@ -63,7 +50,6 @@ module RBS
|
|
|
63
50
|
@env = Environment.from_loader(loader).resolve_type_names
|
|
64
51
|
@builder = DefinitionBuilder.new(env: @env)
|
|
65
52
|
@validator = Validator.new(env: @env)
|
|
66
|
-
exit_error = false
|
|
67
53
|
limit = nil #: Integer?
|
|
68
54
|
OptionParser.new do |opts|
|
|
69
55
|
opts.banner = <<EOU
|
|
@@ -80,14 +66,14 @@ EOU
|
|
|
80
66
|
RBS.print_warning { "`--silent` option is deprecated because it's silent by default. You can use --log-level option of rbs command to display more information." }
|
|
81
67
|
end
|
|
82
68
|
opts.on("--[no-]exit-error-on-syntax-error", "exit(1) if syntax error is detected") {|bool|
|
|
83
|
-
|
|
69
|
+
RBS.print_warning { "`--exit-error-on-syntax-error` option is deprecated because it's validated during parsing.." }
|
|
84
70
|
}
|
|
85
71
|
opts.on("--fail-fast", "Exit immediately as soon as a validation error is found.") do |arg|
|
|
86
72
|
limit = 1
|
|
87
73
|
end
|
|
88
74
|
end.parse!(args)
|
|
89
75
|
|
|
90
|
-
@errors = Errors.new(limit: limit
|
|
76
|
+
@errors = Errors.new(limit: limit)
|
|
91
77
|
end
|
|
92
78
|
|
|
93
79
|
def run
|
|
@@ -122,7 +108,6 @@ EOU
|
|
|
122
108
|
entry.each_decl do |decl|
|
|
123
109
|
if super_class = decl.super_class
|
|
124
110
|
super_class.args.each do |arg|
|
|
125
|
-
no_classish_type_validator(arg)
|
|
126
111
|
@validator.validate_type(arg, context: nil)
|
|
127
112
|
end
|
|
128
113
|
end
|
|
@@ -131,7 +116,6 @@ EOU
|
|
|
131
116
|
entry.each_decl do |decl|
|
|
132
117
|
decl.self_types.each do |self_type|
|
|
133
118
|
self_type.args.each do |arg|
|
|
134
|
-
no_classish_type_validator(arg)
|
|
135
119
|
@validator.validate_type(arg, context: nil)
|
|
136
120
|
end
|
|
137
121
|
|
|
@@ -159,17 +143,14 @@ EOU
|
|
|
159
143
|
|
|
160
144
|
d.type_params.each do |param|
|
|
161
145
|
if ub = param.upper_bound_type
|
|
162
|
-
no_classish_type_validator(ub)
|
|
163
146
|
@validator.validate_type(ub, context: nil)
|
|
164
147
|
end
|
|
165
148
|
|
|
166
149
|
if lb = param.lower_bound_type
|
|
167
|
-
no_classish_type_validator(lb)
|
|
168
150
|
@validator.validate_type(lb, context: nil)
|
|
169
151
|
end
|
|
170
152
|
|
|
171
153
|
if dt = param.default_type
|
|
172
|
-
no_classish_type_validator(dt)
|
|
173
154
|
@validator.validate_type(dt, context: nil)
|
|
174
155
|
end
|
|
175
156
|
end
|
|
@@ -230,17 +211,14 @@ EOU
|
|
|
230
211
|
|
|
231
212
|
decl.decl.type_params.each do |param|
|
|
232
213
|
if ub = param.upper_bound_type
|
|
233
|
-
no_classish_type_validator(ub)
|
|
234
214
|
@validator.validate_type(ub, context: nil)
|
|
235
215
|
end
|
|
236
216
|
|
|
237
217
|
if lb = param.lower_bound_type
|
|
238
|
-
no_classish_type_validator(lb)
|
|
239
218
|
@validator.validate_type(lb, context: nil)
|
|
240
219
|
end
|
|
241
220
|
|
|
242
221
|
if dt = param.default_type
|
|
243
|
-
no_classish_type_validator(dt)
|
|
244
222
|
@validator.validate_type(dt, context: nil)
|
|
245
223
|
end
|
|
246
224
|
end
|
|
@@ -251,9 +229,6 @@ EOU
|
|
|
251
229
|
case member
|
|
252
230
|
when AST::Members::MethodDefinition
|
|
253
231
|
@validator.validate_method_definition(member, type_name: name)
|
|
254
|
-
member.overloads.each do |ov|
|
|
255
|
-
no_classish_type_validator(ov.method_type)
|
|
256
|
-
end
|
|
257
232
|
end
|
|
258
233
|
end
|
|
259
234
|
rescue BaseError => error
|
|
@@ -266,7 +241,6 @@ EOU
|
|
|
266
241
|
RBS.logger.info "Validating constant: `#{name}`..."
|
|
267
242
|
@validator.validate_type const.decl.type, context: const.context
|
|
268
243
|
@builder.ensure_namespace!(name.namespace, location: const.decl.location)
|
|
269
|
-
no_classish_type_validator(const.decl.type)
|
|
270
244
|
rescue BaseError => error
|
|
271
245
|
@errors.add(error)
|
|
272
246
|
end
|
|
@@ -276,7 +250,6 @@ EOU
|
|
|
276
250
|
@env.global_decls.each do |name, global|
|
|
277
251
|
RBS.logger.info "Validating global: `#{name}`..."
|
|
278
252
|
@validator.validate_type global.decl.type, context: nil
|
|
279
|
-
no_classish_type_validator(global.decl.type)
|
|
280
253
|
rescue BaseError => error
|
|
281
254
|
@errors.add(error)
|
|
282
255
|
end
|
|
@@ -299,51 +272,23 @@ EOU
|
|
|
299
272
|
|
|
300
273
|
decl.decl.type_params.each do |param|
|
|
301
274
|
if ub = param.upper_bound_type
|
|
302
|
-
no_classish_type_validator(ub)
|
|
303
275
|
@validator.validate_type(ub, context: nil)
|
|
304
276
|
end
|
|
305
277
|
|
|
306
278
|
if lb = param.lower_bound_type
|
|
307
|
-
no_classish_type_validator(lb)
|
|
308
279
|
@validator.validate_type(lb, context: nil)
|
|
309
280
|
end
|
|
310
281
|
|
|
311
282
|
if dt = param.default_type
|
|
312
|
-
no_classish_type_validator(dt)
|
|
313
283
|
@validator.validate_type(dt, context: nil)
|
|
314
284
|
end
|
|
315
285
|
end
|
|
316
286
|
|
|
317
287
|
TypeParamDefaultReferenceError.check!(decl.decl.type_params)
|
|
318
|
-
|
|
319
|
-
no_classish_type_validator(decl.decl.type)
|
|
320
288
|
rescue BaseError => error
|
|
321
289
|
@errors.add(error)
|
|
322
290
|
end
|
|
323
291
|
end
|
|
324
|
-
|
|
325
|
-
private
|
|
326
|
-
|
|
327
|
-
def no_self_type_validator(type)
|
|
328
|
-
if type.has_self_type?
|
|
329
|
-
@errors.add WillSyntaxError.new("`self` type is not allowed in this context", location: type.location)
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
def no_classish_type_validator(type)
|
|
334
|
-
if type.has_classish_type?
|
|
335
|
-
@errors.add WillSyntaxError.new("`instance` or `class` type is not allowed in this context", location: type.location)
|
|
336
|
-
end
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
def void_type_context_validator(type, allowed_here = false)
|
|
340
|
-
if allowed_here
|
|
341
|
-
return if type.is_a?(Types::Bases::Void)
|
|
342
|
-
end
|
|
343
|
-
if type.with_nonreturn_void? # steep:ignore DeprecatedReference
|
|
344
|
-
@errors.add WillSyntaxError.new("`void` type is only allowed in return type or generics parameter", location: type.location)
|
|
345
|
-
end
|
|
346
|
-
end
|
|
347
292
|
end
|
|
348
293
|
end
|
|
349
294
|
end
|
|
@@ -8,13 +8,17 @@ module RBS
|
|
|
8
8
|
"mutex_m" => ">= 0.3.0",
|
|
9
9
|
"abbrev" => nil,
|
|
10
10
|
"base64" => nil,
|
|
11
|
+
"benchmark" => nil,
|
|
11
12
|
"bigdecimal" => nil,
|
|
12
13
|
"csv" => nil,
|
|
14
|
+
"kconv" => nil,
|
|
15
|
+
"logger" => nil,
|
|
13
16
|
"minitest" => nil,
|
|
14
17
|
"net-smtp" => nil,
|
|
15
18
|
"nkf" => nil,
|
|
16
19
|
"observer" => nil,
|
|
17
20
|
"cgi" => nil,
|
|
21
|
+
"pstore" => nil,
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
class GemfileLockMismatchError < StandardError
|
|
@@ -172,8 +176,8 @@ module RBS
|
|
|
172
176
|
return if lockfile.gems.key?(name)
|
|
173
177
|
|
|
174
178
|
case name
|
|
175
|
-
when 'bigdecimal-math'
|
|
176
|
-
#
|
|
179
|
+
when 'bigdecimal-math', 'kconv'
|
|
180
|
+
# These gems are never released as a gem.
|
|
177
181
|
# Therefore, `assign_gem` should not be called.
|
|
178
182
|
RBS.logger.info {
|
|
179
183
|
from = from_gem || "rbs_collection.yaml"
|