rbs 4.0.0.dev.4 → 4.0.0.dev.5

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.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +11 -8
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/dependabot.yml +1 -1
  7. data/.github/workflows/ruby.yml +17 -34
  8. data/.github/workflows/typecheck.yml +2 -2
  9. data/.github/workflows/valgrind.yml +42 -0
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/README.md +1 -1
  13. data/Rakefile +32 -5
  14. data/config.yml +46 -0
  15. data/core/array.rbs +96 -46
  16. data/core/binding.rbs +0 -2
  17. data/core/builtin.rbs +2 -2
  18. data/core/comparable.rbs +13 -6
  19. data/core/complex.rbs +55 -41
  20. data/core/dir.rbs +4 -4
  21. data/core/encoding.rbs +7 -10
  22. data/core/enumerable.rbs +90 -3
  23. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  24. data/core/enumerator.rbs +63 -1
  25. data/core/errno.rbs +8 -0
  26. data/core/errors.rbs +28 -1
  27. data/core/exception.rbs +2 -2
  28. data/core/fiber.rbs +40 -20
  29. data/core/file.rbs +108 -78
  30. data/core/file_test.rbs +1 -1
  31. data/core/float.rbs +225 -69
  32. data/core/gc.rbs +417 -281
  33. data/core/hash.rbs +1023 -727
  34. data/core/integer.rbs +104 -110
  35. data/core/io/buffer.rbs +21 -10
  36. data/core/io/wait.rbs +11 -33
  37. data/core/io.rbs +82 -19
  38. data/core/kernel.rbs +70 -59
  39. data/core/marshal.rbs +1 -1
  40. data/core/match_data.rbs +1 -1
  41. data/core/math.rbs +42 -3
  42. data/core/method.rbs +63 -27
  43. data/core/module.rbs +103 -26
  44. data/core/nil_class.rbs +3 -3
  45. data/core/numeric.rbs +43 -35
  46. data/core/object.rbs +3 -3
  47. data/core/object_space.rbs +21 -15
  48. data/core/pathname.rbs +1272 -0
  49. data/core/proc.rbs +30 -25
  50. data/core/process.rbs +4 -2
  51. data/core/ractor.rbs +361 -509
  52. data/core/random.rbs +17 -0
  53. data/core/range.rbs +113 -16
  54. data/core/rational.rbs +56 -85
  55. data/core/rbs/unnamed/argf.rbs +2 -2
  56. data/core/rbs/unnamed/env_class.rbs +1 -1
  57. data/core/rbs/unnamed/random.rbs +4 -113
  58. data/core/regexp.rbs +25 -20
  59. data/core/ruby.rbs +53 -0
  60. data/core/ruby_vm.rbs +6 -4
  61. data/core/rubygems/errors.rbs +3 -70
  62. data/core/rubygems/rubygems.rbs +11 -79
  63. data/core/rubygems/version.rbs +2 -3
  64. data/core/set.rbs +488 -359
  65. data/core/signal.rbs +24 -14
  66. data/core/string.rbs +3171 -1241
  67. data/core/struct.rbs +1 -1
  68. data/core/symbol.rbs +17 -11
  69. data/core/thread.rbs +95 -33
  70. data/core/time.rbs +35 -9
  71. data/core/trace_point.rbs +7 -4
  72. data/core/unbound_method.rbs +14 -6
  73. data/docs/aliases.md +79 -0
  74. data/docs/collection.md +2 -2
  75. data/docs/encoding.md +56 -0
  76. data/docs/gem.md +0 -1
  77. data/docs/inline.md +470 -0
  78. data/docs/sigs.md +3 -3
  79. data/docs/syntax.md +33 -4
  80. data/docs/type_fingerprint.md +21 -0
  81. data/exe/rbs +1 -1
  82. data/ext/rbs_extension/ast_translation.c +77 -3
  83. data/ext/rbs_extension/ast_translation.h +3 -0
  84. data/ext/rbs_extension/class_constants.c +8 -2
  85. data/ext/rbs_extension/class_constants.h +4 -0
  86. data/ext/rbs_extension/extconf.rb +5 -1
  87. data/ext/rbs_extension/legacy_location.c +5 -5
  88. data/ext/rbs_extension/main.c +37 -20
  89. data/include/rbs/ast.h +85 -38
  90. data/include/rbs/defines.h +27 -0
  91. data/include/rbs/lexer.h +30 -11
  92. data/include/rbs/parser.h +6 -6
  93. data/include/rbs/string.h +0 -2
  94. data/include/rbs/util/rbs_allocator.h +34 -13
  95. data/include/rbs/util/rbs_assert.h +12 -1
  96. data/include/rbs/util/rbs_encoding.h +2 -0
  97. data/include/rbs/util/rbs_unescape.h +2 -1
  98. data/lib/rbs/ast/annotation.rb +1 -1
  99. data/lib/rbs/ast/comment.rb +1 -1
  100. data/lib/rbs/ast/declarations.rb +10 -10
  101. data/lib/rbs/ast/members.rb +14 -14
  102. data/lib/rbs/ast/ruby/annotations.rb +137 -0
  103. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  104. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  105. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  106. data/lib/rbs/ast/ruby/members.rb +159 -1
  107. data/lib/rbs/ast/type_param.rb +24 -4
  108. data/lib/rbs/buffer.rb +20 -15
  109. data/lib/rbs/cli/diff.rb +16 -15
  110. data/lib/rbs/cli/validate.rb +38 -51
  111. data/lib/rbs/cli.rb +52 -19
  112. data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
  113. data/lib/rbs/collection/sources/git.rb +1 -0
  114. data/lib/rbs/definition.rb +1 -1
  115. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  116. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  117. data/lib/rbs/definition_builder.rb +91 -2
  118. data/lib/rbs/diff.rb +7 -1
  119. data/lib/rbs/environment.rb +227 -74
  120. data/lib/rbs/environment_loader.rb +0 -6
  121. data/lib/rbs/errors.rb +27 -7
  122. data/lib/rbs/inline_parser.rb +341 -5
  123. data/lib/rbs/location_aux.rb +1 -1
  124. data/lib/rbs/locator.rb +5 -1
  125. data/lib/rbs/method_type.rb +5 -3
  126. data/lib/rbs/parser_aux.rb +2 -2
  127. data/lib/rbs/prototype/rb.rb +2 -2
  128. data/lib/rbs/prototype/rbi.rb +2 -0
  129. data/lib/rbs/prototype/runtime.rb +8 -0
  130. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  131. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  132. data/lib/rbs/subtractor.rb +3 -1
  133. data/lib/rbs/test/type_check.rb +16 -2
  134. data/lib/rbs/type_name.rb +1 -1
  135. data/lib/rbs/types.rb +27 -27
  136. data/lib/rbs/validator.rb +2 -2
  137. data/lib/rbs/version.rb +1 -1
  138. data/lib/rbs.rb +1 -1
  139. data/lib/rdoc/discover.rb +1 -1
  140. data/lib/rdoc_plugin/parser.rb +1 -1
  141. data/rbs.gemspec +3 -2
  142. data/schema/typeParam.json +17 -1
  143. data/sig/ast/ruby/annotations.rbs +124 -0
  144. data/sig/ast/ruby/comment_block.rbs +8 -0
  145. data/sig/ast/ruby/declarations.rbs +102 -4
  146. data/sig/ast/ruby/members.rbs +87 -1
  147. data/sig/cli/diff.rbs +5 -11
  148. data/sig/cli/validate.rbs +13 -4
  149. data/sig/cli.rbs +18 -18
  150. data/sig/definition.rbs +6 -1
  151. data/sig/environment.rbs +70 -12
  152. data/sig/errors.rbs +13 -6
  153. data/sig/inline_parser.rbs +39 -2
  154. data/sig/locator.rbs +0 -2
  155. data/sig/manifest.yaml +0 -1
  156. data/sig/method_builder.rbs +3 -1
  157. data/sig/method_types.rbs +1 -1
  158. data/sig/parser.rbs +16 -2
  159. data/sig/resolver/type_name_resolver.rbs +35 -7
  160. data/sig/source.rbs +3 -3
  161. data/sig/type_param.rbs +13 -8
  162. data/sig/types.rbs +4 -4
  163. data/src/ast.c +80 -1
  164. data/src/lexer.c +1392 -1313
  165. data/src/lexer.re +3 -0
  166. data/src/lexstate.c +58 -37
  167. data/src/location.c +4 -4
  168. data/src/parser.c +412 -145
  169. data/src/string.c +0 -48
  170. data/src/util/rbs_allocator.c +89 -71
  171. data/src/util/rbs_assert.c +1 -1
  172. data/src/util/rbs_buffer.c +2 -2
  173. data/src/util/rbs_constant_pool.c +10 -10
  174. data/src/util/rbs_encoding.c +4 -8
  175. data/src/util/rbs_unescape.c +56 -20
  176. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  177. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  178. data/stdlib/cgi/0/core.rbs +9 -393
  179. data/stdlib/cgi/0/manifest.yaml +1 -0
  180. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  181. data/stdlib/coverage/0/coverage.rbs +3 -1
  182. data/stdlib/date/0/date.rbs +67 -59
  183. data/stdlib/date/0/date_time.rbs +1 -1
  184. data/stdlib/delegate/0/delegator.rbs +10 -7
  185. data/stdlib/digest/0/digest.rbs +110 -0
  186. data/stdlib/erb/0/erb.rbs +737 -347
  187. data/stdlib/fileutils/0/fileutils.rbs +20 -14
  188. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  189. data/stdlib/json/0/json.rbs +82 -28
  190. data/stdlib/net-http/0/net-http.rbs +3 -0
  191. data/stdlib/objspace/0/objspace.rbs +9 -27
  192. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  193. data/stdlib/open3/0/open3.rbs +459 -1
  194. data/stdlib/openssl/0/openssl.rbs +331 -228
  195. data/stdlib/optparse/0/optparse.rbs +8 -3
  196. data/stdlib/pathname/0/pathname.rbs +9 -1379
  197. data/stdlib/psych/0/psych.rbs +4 -4
  198. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  199. data/stdlib/rdoc/0/code_object.rbs +2 -1
  200. data/stdlib/rdoc/0/parser.rbs +1 -1
  201. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  202. data/stdlib/rdoc/0/store.rbs +1 -1
  203. data/stdlib/resolv/0/resolv.rbs +25 -68
  204. data/stdlib/ripper/0/ripper.rbs +2 -2
  205. data/stdlib/securerandom/0/manifest.yaml +2 -0
  206. data/stdlib/securerandom/0/securerandom.rbs +6 -19
  207. data/stdlib/singleton/0/singleton.rbs +3 -0
  208. data/stdlib/socket/0/socket.rbs +13 -1
  209. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  210. data/stdlib/stringio/0/stringio.rbs +1176 -85
  211. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  212. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  213. data/stdlib/time/0/time.rbs +1 -1
  214. data/stdlib/timeout/0/timeout.rbs +63 -7
  215. data/stdlib/tsort/0/cyclic.rbs +3 -0
  216. data/stdlib/uri/0/common.rbs +16 -2
  217. data/stdlib/uri/0/file.rbs +1 -1
  218. data/stdlib/uri/0/generic.rbs +24 -16
  219. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  220. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  221. data/stdlib/zlib/0/gzip_writer.rbs +1 -1
  222. data/stdlib/zlib/0/zstream.rbs +1 -0
  223. metadata +30 -4
@@ -21,10 +21,18 @@ module RBS
21
21
  finish if @limit == 1
22
22
  end
23
23
 
24
+ def try(&block)
25
+ catch(:finish) do |tag|
26
+ @tag = tag
27
+ yield
28
+ finish()
29
+ end
30
+ end
31
+
24
32
  def finish
25
33
  if @errors.empty?
26
34
  if @exit_error && @has_syntax_error
27
- exit 1
35
+ throw @tag, 1
28
36
  else
29
37
  # success
30
38
  end
@@ -32,8 +40,10 @@ module RBS
32
40
  @errors.each do |error|
33
41
  RBS.logger.error(build_message(error))
34
42
  end
35
- exit 1
43
+ throw @tag, 1
36
44
  end
45
+
46
+ 0
37
47
  end
38
48
 
39
49
  private
@@ -81,14 +91,14 @@ EOU
81
91
  end
82
92
 
83
93
  def run
84
- validate_class_module_definition
85
- validate_class_module_alias_definition
86
- validate_interface
87
- validate_constant
88
- validate_global
89
- validate_type_alias
90
-
91
- @errors.finish
94
+ @errors.try do
95
+ validate_class_module_definition
96
+ validate_class_module_alias_definition
97
+ validate_interface
98
+ validate_constant
99
+ validate_global
100
+ validate_type_alias
101
+ end
92
102
  end
93
103
 
94
104
  private
@@ -112,8 +122,6 @@ EOU
112
122
  entry.each_decl do |decl|
113
123
  if super_class = decl.super_class
114
124
  super_class.args.each do |arg|
115
- void_type_context_validator(arg, true)
116
- no_self_type_validator(arg)
117
125
  no_classish_type_validator(arg)
118
126
  @validator.validate_type(arg, context: nil)
119
127
  end
@@ -123,15 +131,13 @@ EOU
123
131
  entry.each_decl do |decl|
124
132
  decl.self_types.each do |self_type|
125
133
  self_type.args.each do |arg|
126
- void_type_context_validator(arg, true)
127
- no_self_type_validator(arg)
128
134
  no_classish_type_validator(arg)
129
135
  @validator.validate_type(arg, context: nil)
130
136
  end
131
137
 
132
138
  self_params =
133
139
  if self_type.name.class?
134
- @env.normalized_module_entry(self_type.name)&.type_params
140
+ @env.module_entry(self_type.name, normalized: true)&.type_params
135
141
  else
136
142
  @env.interface_decls[self_type.name]&.decl&.type_params
137
143
  end
@@ -153,15 +159,16 @@ EOU
153
159
 
154
160
  d.type_params.each do |param|
155
161
  if ub = param.upper_bound_type
156
- void_type_context_validator(ub)
157
- no_self_type_validator(ub)
158
162
  no_classish_type_validator(ub)
159
163
  @validator.validate_type(ub, context: nil)
160
164
  end
161
165
 
166
+ if lb = param.lower_bound_type
167
+ no_classish_type_validator(lb)
168
+ @validator.validate_type(lb, context: nil)
169
+ end
170
+
162
171
  if dt = param.default_type
163
- void_type_context_validator(dt, true)
164
- no_self_type_validator(dt)
165
172
  no_classish_type_validator(dt)
166
173
  @validator.validate_type(dt, context: nil)
167
174
  end
@@ -176,21 +183,10 @@ EOU
176
183
  case member
177
184
  when AST::Members::MethodDefinition
178
185
  @validator.validate_method_definition(member, type_name: name)
179
- member.overloads.each do |ov|
180
- void_type_context_validator(ov.method_type)
181
- end
182
- when AST::Members::Attribute
183
- void_type_context_validator(member.type)
184
186
  when AST::Members::Mixin
185
- member.args.each do |arg|
186
- no_self_type_validator(arg)
187
- unless arg.is_a?(Types::Bases::Void)
188
- void_type_context_validator(arg, true)
189
- end
190
- end
191
187
  params =
192
188
  if member.name.class?
193
- module_decl = @env.normalized_module_entry(member.name) or raise
189
+ module_decl = @env.module_entry(member.name, normalized: true) or raise
194
190
  module_decl.type_params
195
191
  else
196
192
  interface_decl = @env.interface_decls.fetch(member.name)
@@ -199,10 +195,6 @@ EOU
199
195
  InvalidTypeApplicationError.check!(type_name: member.name, params: params, args: member.args, location: member.location)
200
196
  when AST::Members::Var
201
197
  @validator.validate_variable(member)
202
- void_type_context_validator(member.type)
203
- if member.is_a?(AST::Members::ClassVariable)
204
- no_self_type_validator(member.type)
205
- end
206
198
  end
207
199
  end
208
200
  else
@@ -238,15 +230,16 @@ EOU
238
230
 
239
231
  decl.decl.type_params.each do |param|
240
232
  if ub = param.upper_bound_type
241
- void_type_context_validator(ub)
242
- no_self_type_validator(ub)
243
233
  no_classish_type_validator(ub)
244
234
  @validator.validate_type(ub, context: nil)
245
235
  end
246
236
 
237
+ if lb = param.lower_bound_type
238
+ no_classish_type_validator(lb)
239
+ @validator.validate_type(lb, context: nil)
240
+ end
241
+
247
242
  if dt = param.default_type
248
- void_type_context_validator(dt, true)
249
- no_self_type_validator(dt)
250
243
  no_classish_type_validator(dt)
251
244
  @validator.validate_type(dt, context: nil)
252
245
  end
@@ -259,7 +252,6 @@ EOU
259
252
  when AST::Members::MethodDefinition
260
253
  @validator.validate_method_definition(member, type_name: name)
261
254
  member.overloads.each do |ov|
262
- void_type_context_validator(ov.method_type)
263
255
  no_classish_type_validator(ov.method_type)
264
256
  end
265
257
  end
@@ -274,9 +266,7 @@ EOU
274
266
  RBS.logger.info "Validating constant: `#{name}`..."
275
267
  @validator.validate_type const.decl.type, context: const.context
276
268
  @builder.ensure_namespace!(name.namespace, location: const.decl.location)
277
- no_self_type_validator(const.decl.type)
278
269
  no_classish_type_validator(const.decl.type)
279
- void_type_context_validator(const.decl.type)
280
270
  rescue BaseError => error
281
271
  @errors.add(error)
282
272
  end
@@ -286,9 +276,7 @@ EOU
286
276
  @env.global_decls.each do |name, global|
287
277
  RBS.logger.info "Validating global: `#{name}`..."
288
278
  @validator.validate_type global.decl.type, context: nil
289
- no_self_type_validator(global.decl.type)
290
279
  no_classish_type_validator(global.decl.type)
291
- void_type_context_validator(global.decl.type)
292
280
  rescue BaseError => error
293
281
  @errors.add(error)
294
282
  end
@@ -311,15 +299,16 @@ EOU
311
299
 
312
300
  decl.decl.type_params.each do |param|
313
301
  if ub = param.upper_bound_type
314
- void_type_context_validator(ub)
315
- no_self_type_validator(ub)
316
302
  no_classish_type_validator(ub)
317
303
  @validator.validate_type(ub, context: nil)
318
304
  end
319
305
 
306
+ if lb = param.lower_bound_type
307
+ no_classish_type_validator(lb)
308
+ @validator.validate_type(lb, context: nil)
309
+ end
310
+
320
311
  if dt = param.default_type
321
- void_type_context_validator(dt, true)
322
- no_self_type_validator(dt)
323
312
  no_classish_type_validator(dt)
324
313
  @validator.validate_type(dt, context: nil)
325
314
  end
@@ -327,9 +316,7 @@ EOU
327
316
 
328
317
  TypeParamDefaultReferenceError.check!(decl.decl.type_params)
329
318
 
330
- no_self_type_validator(decl.decl.type)
331
319
  no_classish_type_validator(decl.decl.type)
332
- void_type_context_validator(decl.decl.type)
333
320
  rescue BaseError => error
334
321
  @errors.add(error)
335
322
  end
@@ -353,7 +340,7 @@ EOU
353
340
  if allowed_here
354
341
  return if type.is_a?(Types::Bases::Void)
355
342
  end
356
- if type.with_nonreturn_void?
343
+ if type.with_nonreturn_void? # steep:ignore DeprecatedReference
357
344
  @errors.add WillSyntaxError.new("`void` type is only allowed in return type or generics parameter", location: type.location)
358
345
  end
359
346
  end
data/lib/rbs/cli.rb CHANGED
@@ -136,10 +136,12 @@ module RBS
136
136
  case command
137
137
  when :version
138
138
  stdout.puts opts.ver
139
+ 0
139
140
  when *COMMANDS
140
141
  __send__ :"run_#{command}", args, options
141
142
  else
142
143
  stdout.puts opts.help
144
+ 0
143
145
  end
144
146
  end
145
147
 
@@ -191,6 +193,8 @@ EOB
191
193
 
192
194
  stdout.print JSON.generate(decls)
193
195
  stdout.flush
196
+
197
+ 0
194
198
  end
195
199
 
196
200
  def run_list(args, options)
@@ -254,6 +258,8 @@ EOB
254
258
  stdout.puts "#{name} (interface)"
255
259
  end
256
260
  end
261
+
262
+ 0
257
263
  end
258
264
 
259
265
  def run_ancestors(args, options)
@@ -279,7 +285,7 @@ EOU
279
285
 
280
286
  unless args.size == 1
281
287
  stdout.puts "Expected one argument."
282
- return
288
+ return 1
283
289
  end
284
290
 
285
291
  loader = options.loader()
@@ -317,6 +323,8 @@ EOU
317
323
  else
318
324
  stdout.puts "Cannot find class: #{type_name}"
319
325
  end
326
+
327
+ 0
320
328
  end
321
329
 
322
330
  def run_methods(args, options)
@@ -344,7 +352,7 @@ EOU
344
352
 
345
353
  unless args.size == 1
346
354
  stdout.puts "Expected one argument."
347
- return
355
+ return 1
348
356
  end
349
357
 
350
358
  loader = options.loader()
@@ -373,6 +381,8 @@ EOU
373
381
  else
374
382
  stdout.puts "Cannot find class: #{type_name}"
375
383
  end
384
+
385
+ 0
376
386
  end
377
387
 
378
388
  def run_method(args, options)
@@ -398,7 +408,7 @@ EOU
398
408
 
399
409
  unless args.size == 2
400
410
  stdout.puts "Expected two arguments, but given #{args.size}."
401
- return
411
+ return 1
402
412
  end
403
413
 
404
414
  loader = options.loader()
@@ -410,7 +420,7 @@ EOU
410
420
 
411
421
  unless env.module_name?(type_name)
412
422
  stdout.puts "Cannot find class: #{type_name}"
413
- return
423
+ return 1
414
424
  end
415
425
 
416
426
  definition = case kind
@@ -426,7 +436,7 @@ EOU
426
436
 
427
437
  unless method
428
438
  stdout.puts "Cannot find method: #{method_name}"
429
- return
439
+ return 1
430
440
  end
431
441
 
432
442
  stdout.puts "#{type_name}#{kind == :instance ? "#" : "."}#{method_name}"
@@ -440,6 +450,8 @@ EOU
440
450
  stdout.puts format(" %s %-#{length_max}s at %s", separator, type, type.location)
441
451
  separator = "|"
442
452
  end
453
+
454
+ 0
443
455
  end
444
456
 
445
457
  def run_validate(args, options)
@@ -469,7 +481,7 @@ EOU
469
481
 
470
482
  unless args.size == 1
471
483
  stdout.puts "Expected one argument."
472
- return
484
+ return 1
473
485
  end
474
486
 
475
487
  loader = options.loader()
@@ -502,6 +514,8 @@ EOU
502
514
  else
503
515
  stdout.puts " => [no constant]"
504
516
  end
517
+
518
+ 0
505
519
  end
506
520
 
507
521
  def run_paths(args, options)
@@ -544,6 +558,8 @@ EOU
544
558
  stdout.puts "#{dir} (#{kind_of[dir]}, library, name=#{source.name})"
545
559
  end
546
560
  end
561
+
562
+ 0
547
563
  end
548
564
 
549
565
  def run_prototype(args, options)
@@ -647,6 +663,8 @@ EOU
647
663
 
648
664
  writer = Writer.new(out: stdout)
649
665
  writer.write decls
666
+
667
+ 0
650
668
  else
651
669
  stdout.puts <<EOU
652
670
  Usage: rbs prototype [generator...] [args...]
@@ -660,7 +678,7 @@ Examples:
660
678
  $ rbs prototype rbi foo.rbi
661
679
  $ rbs prototype runtime String
662
680
  EOU
663
- exit 1
681
+ 1
664
682
  end
665
683
  end
666
684
 
@@ -712,12 +730,12 @@ EOU
712
730
 
713
731
  unless has_parser?
714
732
  stdout.puts "Not supported on this interpreter (#{RUBY_ENGINE})."
715
- exit 1
733
+ return 1
716
734
  end
717
735
 
718
736
  if args.empty?
719
737
  stdout.puts opts
720
- return nil
738
+ return 1
721
739
  end
722
740
 
723
741
  new_parser = -> do
@@ -827,6 +845,8 @@ EOU
827
845
  writer = Writer.new(out: stdout)
828
846
  writer.write parser.decls
829
847
  end
848
+
849
+ 0
830
850
  end
831
851
 
832
852
  def run_vendor(args, options)
@@ -880,6 +900,8 @@ Options:
880
900
 
881
901
  stdout.puts " Copying RBS files..."
882
902
  vendorer.copy!
903
+
904
+ 0
883
905
  end
884
906
 
885
907
  def run_parse(args, options)
@@ -927,7 +949,11 @@ Options:
927
949
  syntax_error = true
928
950
  end
929
951
 
930
- exit 1 if syntax_error
952
+ if syntax_error
953
+ 1
954
+ else
955
+ 0
956
+ end
931
957
  end
932
958
 
933
959
  def run_annotate(args, options)
@@ -946,7 +972,7 @@ Import documents from RDoc and update RBS files.
946
972
 
947
973
  Examples:
948
974
 
949
- $ rbs annotate stdlib/pathname/**/*.rbs
975
+ $ rbs annotate stdlib/logger/**/*.rbs
950
976
 
951
977
  Options:
952
978
  EOB
@@ -975,6 +1001,8 @@ Options:
975
1001
  annotator.annotate_file(path, preserve: preserve)
976
1002
  end
977
1003
  end
1004
+
1005
+ 0
978
1006
  end
979
1007
 
980
1008
  def test_opt options
@@ -1028,7 +1056,7 @@ EOB
1028
1056
 
1029
1057
  if args.length.zero?
1030
1058
  stdout.puts opts.help
1031
- exit 1
1059
+ return 1
1032
1060
  end
1033
1061
 
1034
1062
  # @type var env_hash: Hash[String, String?]
@@ -1044,11 +1072,12 @@ EOB
1044
1072
 
1045
1073
  # @type var out: String
1046
1074
  # @type var err: String
1075
+ # @type var status: Process::Status
1047
1076
  out, err, status = __skip__ = Open3.capture3(env_hash, *args)
1048
1077
  stdout.print(out)
1049
1078
  stderr.print(err)
1050
1079
 
1051
- status
1080
+ status.to_i
1052
1081
  end
1053
1082
 
1054
1083
  def run_collection(args, options)
@@ -1073,7 +1102,7 @@ EOB
1073
1102
  when 'init'
1074
1103
  if config_path.exist?
1075
1104
  puts "#{config_path} already exists"
1076
- exit 1
1105
+ return 1
1077
1106
  end
1078
1107
 
1079
1108
  config_path.write(<<~'YAML')
@@ -1101,15 +1130,17 @@ EOB
1101
1130
  when 'clean'
1102
1131
  unless lock_path.exist?
1103
1132
  puts "#{lock_path} should exist to clean"
1104
- exit 1
1133
+ return 1
1105
1134
  end
1106
1135
  Collection::Cleaner.new(lockfile_path: lock_path)
1107
1136
  when 'help', 'hel', 'he', 'h'
1108
1137
  puts opts.help
1109
1138
  else
1110
1139
  puts opts.help
1111
- exit 1
1140
+ return 1
1112
1141
  end
1142
+
1143
+ 0
1113
1144
  end
1114
1145
 
1115
1146
  def collection_options(args)
@@ -1171,7 +1202,7 @@ EOB
1171
1202
  *minuend_paths, subtrahend_path = args
1172
1203
  unless subtrahend_path
1173
1204
  stdout.puts opts.help
1174
- exit 1
1205
+ return 1
1175
1206
  end
1176
1207
  subtrahend_paths << subtrahend_path
1177
1208
  else
@@ -1180,7 +1211,7 @@ EOB
1180
1211
 
1181
1212
  if minuend_paths.empty?
1182
1213
  stdout.puts opts.help
1183
- exit 1
1214
+ return 1
1184
1215
  end
1185
1216
 
1186
1217
  subtrahend = Environment.new.tap do |env|
@@ -1213,10 +1244,12 @@ EOB
1213
1244
  end
1214
1245
  end
1215
1246
  end
1247
+
1248
+ 0
1216
1249
  end
1217
1250
 
1218
1251
  def run_diff(argv, library_options)
1219
- Diff.new(argv: argv, library_options: library_options, stdout: stdout, stderr: stderr).run
1252
+ Diff.new(stdout: stdout, stderr: stderr).run(argv: argv, library_options: library_options)
1220
1253
  end
1221
1254
  end
1222
1255
  end
@@ -14,6 +14,7 @@ module RBS
14
14
  "net-smtp" => nil,
15
15
  "nkf" => nil,
16
16
  "observer" => nil,
17
+ "cgi" => nil,
17
18
  }
18
19
 
19
20
  class GemfileLockMismatchError < StandardError
@@ -183,6 +184,13 @@ module RBS
183
184
  lockfile.gems[name] = { name: name, version: "0", source: source }
184
185
  end
185
186
  return
187
+ when 'set', 'pathname'
188
+ # set and pathname is migrated to core from stdlib.
189
+ RBS.logger.info {
190
+ from = from_gem || "rbs_collection.yaml"
191
+ "`#{name}` is a part of the Ruby core library. The dependency to the library can be safely deleted from #{from}."
192
+ }
193
+ return
186
194
  when *ALUMNI_STDLIBS.keys
187
195
  version = ALUMNI_STDLIBS.fetch(name)
188
196
  if from_gem
@@ -3,6 +3,7 @@
3
3
  require 'digest/sha2'
4
4
  require 'open3'
5
5
  require 'find'
6
+ require 'fileutils'
6
7
 
7
8
  module RBS
8
9
  module Collection
@@ -66,7 +66,7 @@ module RBS
66
66
  when AST::Members::Base
67
67
  member.comment
68
68
  when AST::Ruby::Members::Base
69
- nil
69
+ member.leading_comment&.as_comment
70
70
  end
71
71
  end
72
72
 
@@ -220,7 +220,7 @@ module RBS
220
220
  InvalidTypeApplicationError.check2!(type_name: super_class.name, args: super_class.args, env: env, location: super_class.location)
221
221
  end
222
222
 
223
- super_entry = env.normalized_class_entry(super_name) or raise
223
+ super_entry = env.class_entry(super_name, normalized: true) or raise
224
224
  super_args = AST::TypeParam.normalize_args(super_entry.type_params, super_args)
225
225
 
226
226
  ancestors = OneAncestors.class_instance(
@@ -248,7 +248,7 @@ module RBS
248
248
 
249
249
  module_name = module_self.name
250
250
  if module_name.class?
251
- module_entry = env.normalized_module_class_entry(module_name) or raise
251
+ module_entry = env.module_class_entry(module_name, normalized: true) or raise
252
252
  module_name = module_entry.name
253
253
  self_args = AST::TypeParam.normalize_args(module_entry.type_params, module_self.args)
254
254
  end
@@ -361,7 +361,7 @@ module RBS
361
361
  MixinClassError.check!(type_name: type_name, env: env, member: member)
362
362
  NoMixinFoundError.check!(member.name, env: env, member: member)
363
363
 
364
- module_decl = env.normalized_module_entry(module_name) or raise
364
+ module_decl = env.module_entry(module_name, normalized: true) or raise
365
365
  module_args = AST::TypeParam.normalize_args(module_decl.type_params, module_args)
366
366
 
367
367
  module_name = env.normalize_module_name(module_name)
@@ -380,7 +380,7 @@ module RBS
380
380
  MixinClassError.check!(type_name: type_name, env: env, member: member)
381
381
  NoMixinFoundError.check!(member.name, env: env, member: member)
382
382
 
383
- module_decl = env.normalized_module_entry(member.name) or raise
383
+ module_decl = env.module_entry(member.name, normalized: true) or raise
384
384
  module_name = module_decl.name
385
385
 
386
386
  module_args = member.args.map {|type| align_params ? type.sub(align_params) : type }
@@ -398,7 +398,7 @@ module RBS
398
398
  MixinClassError.check!(type_name: type_name, env: env, member: member)
399
399
  NoMixinFoundError.check!(member.name, env: env, member: member)
400
400
 
401
- module_decl = env.normalized_module_entry(module_name) or raise
401
+ module_decl = env.module_entry(module_name, normalized: true) or raise
402
402
  module_args = AST::TypeParam.normalize_args(module_decl.type_params, module_args)
403
403
 
404
404
  module_name = env.normalize_module_name(module_name)
@@ -414,7 +414,60 @@ module RBS
414
414
  end
415
415
  end
416
416
  when AST::Ruby::Declarations::Base
417
- # noop
417
+ decl.members.each do |member|
418
+ case member
419
+ when AST::Ruby::Members::IncludeMember
420
+ if included_modules
421
+ module_name = member.module_name
422
+ module_args = member.type_args
423
+
424
+ # Check if mixing in a class (not allowed)
425
+ if env.class_decl?(module_name)
426
+ raise MixinClassError.new(type_name: type_name, member: member)
427
+ end
428
+
429
+ # Check if module exists
430
+ module_decl = env.module_entry(module_name, normalized: true) or raise NoMixinFoundError.new(type_name: module_name, member: member)
431
+ module_args = AST::TypeParam.normalize_args(module_decl.type_params, module_args)
432
+ module_name = env.normalize_module_name(module_name)
433
+ included_modules << Definition::Ancestor::Instance.new(name: module_name, args: module_args, source: member)
434
+ end
435
+
436
+ when AST::Ruby::Members::ExtendMember
437
+ if extended_modules
438
+ module_name = member.module_name
439
+ module_args = member.type_args
440
+
441
+ # Check if mixing in a class (not allowed)
442
+ if env.class_decl?(module_name)
443
+ raise MixinClassError.new(type_name: type_name, member: member)
444
+ end
445
+
446
+ # Check if module exists
447
+ module_decl = env.module_entry(module_name, normalized: true) or raise NoMixinFoundError.new(type_name: module_name, member: member)
448
+ module_args = AST::TypeParam.normalize_args(module_decl.type_params, module_args)
449
+ module_name = env.normalize_module_name(module_name)
450
+ extended_modules << Definition::Ancestor::Instance.new(name: module_name, args: module_args, source: member)
451
+ end
452
+
453
+ when AST::Ruby::Members::PrependMember
454
+ if prepended_modules
455
+ module_name = member.module_name
456
+ module_args = member.type_args
457
+
458
+ # Check if mixing in a class (not allowed)
459
+ if env.class_decl?(module_name)
460
+ raise MixinClassError.new(type_name: type_name, member: member)
461
+ end
462
+
463
+ # Check if module exists
464
+ module_decl = env.module_entry(module_name, normalized: true) or raise NoMixinFoundError.new(type_name: module_name, member: member)
465
+ module_args = AST::TypeParam.normalize_args(module_decl.type_params, module_args)
466
+ module_name = env.normalize_module_name(module_name)
467
+ prepended_modules << Definition::Ancestor::Instance.new(name: module_name, args: module_args, source: member)
468
+ end
469
+ end
470
+ end
418
471
  end
419
472
  end
420
473
 
@@ -484,7 +537,7 @@ module RBS
484
537
  included_modules.each do |mod|
485
538
  name = mod.name
486
539
  arg_types = mod.args
487
- mod.source.is_a?(AST::Members::Include) or raise
540
+ (mod.source.is_a?(AST::Members::Include) || mod.source.is_a?(AST::Ruby::Members::IncludeMember)) or raise
488
541
  mod_ancestors =
489
542
  instance_ancestors(name, building_ancestors: building_ancestors)
490
543
  .apply(arg_types, env: env, location: mod.source.location)
@@ -499,7 +552,7 @@ module RBS
499
552
  prepended_modules.each do |mod|
500
553
  name = mod.name
501
554
  arg_types = mod.args
502
- mod.source.is_a?(AST::Members::Prepend) or raise
555
+ (mod.source.is_a?(AST::Members::Prepend) || mod.source.is_a?(AST::Ruby::Members::PrependMember)) or raise
503
556
  mod_ancestors =
504
557
  instance_ancestors(name, building_ancestors: building_ancestors)
505
558
  .apply(arg_types, env: env, location: mod.source.location)
@@ -554,7 +607,7 @@ module RBS
554
607
  extended_modules.each do |mod|
555
608
  name = mod.name
556
609
  args = mod.args
557
- mod.source.is_a?(AST::Members::Extend) or raise
610
+ (mod.source.is_a?(AST::Members::Extend) || mod.source.is_a?(AST::Ruby::Members::ExtendMember)) or raise
558
611
  mod_ancestors =
559
612
  instance_ancestors(name, building_ancestors: building_ancestors)
560
613
  .apply(args, env: env, location: mod.source.location)