rbs 3.6.1 → 3.9.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 (268) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -2
  3. data/.github/workflows/dependabot.yml +1 -1
  4. data/.github/workflows/ruby.yml +34 -10
  5. data/.github/workflows/windows.yml +20 -3
  6. data/.gitignore +1 -0
  7. data/.rubocop.yml +26 -1
  8. data/CHANGELOG.md +241 -0
  9. data/Rakefile +54 -4
  10. data/config.yml +317 -0
  11. data/core/array.rbs +1756 -1591
  12. data/core/basic_object.rbs +38 -35
  13. data/core/comparable.rbs +1 -1
  14. data/core/complex.rbs +166 -94
  15. data/core/data.rbs +2 -2
  16. data/core/dir.rbs +2 -18
  17. data/core/encoding.rbs +12 -32
  18. data/core/enumerable.rbs +270 -266
  19. data/core/enumerator.rbs +14 -4
  20. data/core/env.rbs +1 -1
  21. data/core/errno.rbs +33 -16
  22. data/core/errors.rbs +6 -2
  23. data/core/exception.rbs +342 -167
  24. data/core/fiber.rbs +3 -2
  25. data/core/file.rbs +26 -75
  26. data/core/float.rbs +125 -72
  27. data/core/gc.rbs +158 -42
  28. data/core/hash.rbs +122 -143
  29. data/core/integer.rbs +79 -50
  30. data/core/io/buffer.rbs +49 -43
  31. data/core/io.rbs +108 -151
  32. data/core/kernel.rbs +341 -209
  33. data/core/match_data.rbs +76 -2
  34. data/core/math.rbs +0 -36
  35. data/core/method.rbs +2 -2
  36. data/core/module.rbs +32 -27
  37. data/core/nil_class.rbs +2 -2
  38. data/core/numeric.rbs +101 -104
  39. data/core/object.rbs +1 -5
  40. data/core/object_space/weak_key_map.rbs +3 -4
  41. data/core/object_space.rbs +3 -3
  42. data/core/proc.rbs +82 -14
  43. data/core/process.rbs +110 -58
  44. data/core/ractor.rbs +57 -4
  45. data/core/range.rbs +114 -87
  46. data/core/rational.rbs +0 -2
  47. data/core/rbs/unnamed/argf.rbs +237 -36
  48. data/core/rbs/unnamed/env_class.rbs +35 -53
  49. data/core/rbs/unnamed/random.rbs +1 -2
  50. data/core/regexp.rbs +10 -56
  51. data/core/ruby_vm.rbs +88 -9
  52. data/core/rubygems/config_file.rbs +3 -0
  53. data/core/rubygems/errors.rbs +3 -6
  54. data/core/rubygems/platform.rbs +0 -9
  55. data/core/rubygems/rubygems.rbs +3 -6
  56. data/core/rubygems/version.rbs +8 -8
  57. data/core/set.rbs +4 -16
  58. data/core/string.rbs +271 -264
  59. data/core/struct.rbs +6 -18
  60. data/core/symbol.rbs +14 -21
  61. data/core/thread.rbs +32 -35
  62. data/core/time.rbs +131 -50
  63. data/core/trace_point.rbs +124 -113
  64. data/core/true_class.rbs +0 -1
  65. data/core/unbound_method.rbs +1 -1
  66. data/core/warning.rbs +9 -2
  67. data/docs/architecture.md +1 -1
  68. data/docs/syntax.md +17 -10
  69. data/ext/rbs_extension/extconf.rb +11 -0
  70. data/ext/rbs_extension/location.c +61 -29
  71. data/ext/rbs_extension/location.h +4 -3
  72. data/ext/rbs_extension/main.c +23 -1
  73. data/ext/rbs_extension/parser.c +506 -517
  74. data/ext/rbs_extension/parserstate.c +109 -30
  75. data/ext/rbs_extension/parserstate.h +6 -4
  76. data/ext/rbs_extension/rbs_extension.h +1 -10
  77. data/{ext/rbs_extension → include/rbs}/constants.h +21 -19
  78. data/include/rbs/ruby_objs.h +72 -0
  79. data/include/rbs/util/rbs_constant_pool.h +219 -0
  80. data/include/rbs.h +7 -0
  81. data/lib/rbs/annotate/annotations.rb +3 -3
  82. data/lib/rbs/annotate/rdoc_source.rb +2 -2
  83. data/lib/rbs/ast/declarations.rb +9 -4
  84. data/lib/rbs/ast/directives.rb +10 -0
  85. data/lib/rbs/ast/members.rb +2 -0
  86. data/lib/rbs/ast/type_param.rb +2 -12
  87. data/lib/rbs/cli/diff.rb +3 -3
  88. data/lib/rbs/cli/validate.rb +2 -1
  89. data/lib/rbs/cli.rb +16 -16
  90. data/lib/rbs/collection/config/lockfile_generator.rb +58 -8
  91. data/lib/rbs/collection/config.rb +5 -3
  92. data/lib/rbs/collection/sources/rubygems.rb +1 -1
  93. data/lib/rbs/collection.rb +1 -0
  94. data/lib/rbs/definition.rb +51 -34
  95. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -3
  96. data/lib/rbs/definition_builder.rb +83 -24
  97. data/lib/rbs/environment.rb +33 -18
  98. data/lib/rbs/environment_loader.rb +6 -1
  99. data/lib/rbs/errors.rb +24 -0
  100. data/lib/rbs/locator.rb +2 -0
  101. data/lib/rbs/method_type.rb +2 -0
  102. data/lib/rbs/namespace.rb +1 -0
  103. data/lib/rbs/parser_aux.rb +40 -3
  104. data/lib/rbs/prototype/rb.rb +20 -12
  105. data/lib/rbs/prototype/rbi.rb +11 -6
  106. data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
  107. data/lib/rbs/prototype/runtime.rb +7 -5
  108. data/lib/rbs/subtractor.rb +3 -3
  109. data/lib/rbs/test/hook.rb +47 -42
  110. data/lib/rbs/test/type_check.rb +7 -5
  111. data/lib/rbs/type_name.rb +14 -9
  112. data/lib/rbs/types.rb +63 -14
  113. data/lib/rbs/unit_test/spy.rb +4 -2
  114. data/lib/rbs/unit_test/type_assertions.rb +19 -13
  115. data/lib/rbs/unit_test/with_aliases.rb +3 -1
  116. data/lib/rbs/validator.rb +7 -1
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs/writer.rb +10 -5
  119. data/lib/rbs.rb +1 -0
  120. data/lib/rdoc_plugin/parser.rb +2 -2
  121. data/rbs.gemspec +6 -2
  122. data/sig/ancestor_graph.rbs +5 -5
  123. data/sig/annotate/rdoc_source.rbs +2 -0
  124. data/sig/cli.rbs +2 -0
  125. data/sig/collection/config/lockfile_generator.rbs +9 -1
  126. data/sig/declarations.rbs +10 -3
  127. data/sig/definition.rbs +80 -12
  128. data/sig/definition_builder.rbs +18 -4
  129. data/sig/directives.rbs +17 -1
  130. data/sig/environment.rbs +3 -1
  131. data/sig/errors.rbs +19 -0
  132. data/sig/namespace.rbs +2 -3
  133. data/sig/parser.rbs +5 -1
  134. data/sig/prototype/rb.rbs +1 -1
  135. data/sig/resolver/constant_resolver.rbs +2 -2
  136. data/sig/resolver/context.rbs +1 -1
  137. data/sig/subtractor.rbs +1 -1
  138. data/sig/test/type_check.rbs +2 -2
  139. data/sig/type_alias_dependency.rbs +2 -2
  140. data/sig/type_alias_regularity.rbs +6 -6
  141. data/sig/type_param.rbs +4 -4
  142. data/sig/typename.rbs +8 -5
  143. data/sig/types.rbs +1 -1
  144. data/sig/unit_test/spy.rbs +2 -0
  145. data/sig/unit_test/type_assertions.rbs +2 -0
  146. data/sig/use_map.rbs +1 -1
  147. data/sig/validator.rbs +6 -2
  148. data/sig/vendorer.rbs +1 -1
  149. data/sig/writer.rbs +1 -1
  150. data/{ext/rbs_extension → src}/constants.c +35 -36
  151. data/src/ruby_objs.c +799 -0
  152. data/src/util/rbs_constant_pool.c +342 -0
  153. data/stdlib/base64/0/base64.rbs +0 -9
  154. data/stdlib/benchmark/0/benchmark.rbs +11 -2
  155. data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
  156. data/stdlib/cgi/0/core.rbs +60 -3
  157. data/stdlib/cgi/0/manifest.yaml +1 -0
  158. data/stdlib/coverage/0/coverage.rbs +0 -3
  159. data/stdlib/csv/0/csv.rbs +18 -58
  160. data/stdlib/csv/0/manifest.yaml +1 -0
  161. data/stdlib/date/0/date.rbs +27 -42
  162. data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -6
  163. data/stdlib/digest/0/digest.rbs +25 -2
  164. data/stdlib/erb/0/erb.rbs +0 -1
  165. data/stdlib/etc/0/etc.rbs +51 -34
  166. data/stdlib/fileutils/0/fileutils.rbs +3 -44
  167. data/stdlib/io-console/0/io-console.rbs +69 -15
  168. data/stdlib/ipaddr/0/ipaddr.rbs +16 -4
  169. data/stdlib/json/0/json.rbs +107 -120
  170. data/stdlib/logger/0/log_device.rbs +1 -1
  171. data/stdlib/logger/0/logger.rbs +3 -18
  172. data/stdlib/minitest/0/kernel.rbs +2 -2
  173. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
  174. data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
  175. data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
  176. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
  177. data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
  178. data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
  179. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  180. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  181. data/stdlib/minitest/0/minitest/mock.rbs +9 -5
  182. data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
  183. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
  184. data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
  185. data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
  186. data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
  187. data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
  188. data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
  189. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
  190. data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
  191. data/stdlib/minitest/0/minitest/spec.rbs +1 -1
  192. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
  193. data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
  194. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +1 -1
  195. data/stdlib/minitest/0/minitest/test.rbs +7 -14
  196. data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
  197. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  198. data/stdlib/minitest/0/minitest/unit.rbs +1 -2
  199. data/stdlib/minitest/0/minitest.rbs +41 -892
  200. data/stdlib/monitor/0/monitor.rbs +13 -4
  201. data/stdlib/net-http/0/net-http.rbs +42 -109
  202. data/stdlib/nkf/0/nkf.rbs +30 -0
  203. data/stdlib/objspace/0/objspace.rbs +1 -2
  204. data/stdlib/observable/0/observable.rbs +1 -1
  205. data/stdlib/open-uri/0/manifest.yaml +1 -0
  206. data/stdlib/open-uri/0/open-uri.rbs +52 -0
  207. data/stdlib/open3/0/open3.rbs +0 -8
  208. data/stdlib/openssl/0/manifest.yaml +1 -0
  209. data/stdlib/openssl/0/openssl.rbs +235 -143
  210. data/stdlib/optparse/0/optparse.rbs +58 -18
  211. data/stdlib/pathname/0/pathname.rbs +2 -8
  212. data/stdlib/pp/0/pp.rbs +3 -1
  213. data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
  214. data/stdlib/pstore/0/pstore.rbs +0 -6
  215. data/stdlib/psych/0/core_ext.rbs +12 -0
  216. data/stdlib/psych/0/psych.rbs +15 -4
  217. data/stdlib/pty/0/pty.rbs +46 -4
  218. data/stdlib/rdoc/0/code_object.rbs +0 -4
  219. data/stdlib/rdoc/0/markup.rbs +10 -12
  220. data/stdlib/rdoc/0/rdoc.rbs +13 -8
  221. data/stdlib/resolv/0/resolv.rbs +21 -12
  222. data/stdlib/ripper/0/ripper.rbs +0 -2
  223. data/stdlib/securerandom/0/securerandom.rbs +7 -2
  224. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  225. data/stdlib/singleton/0/singleton.rbs +0 -1
  226. data/stdlib/socket/0/addrinfo.rbs +1 -2
  227. data/stdlib/socket/0/basic_socket.rbs +0 -5
  228. data/stdlib/socket/0/socket.rbs +32 -27
  229. data/stdlib/socket/0/tcp_server.rbs +0 -3
  230. data/stdlib/socket/0/tcp_socket.rbs +36 -3
  231. data/stdlib/socket/0/udp_socket.rbs +0 -1
  232. data/stdlib/socket/0/unix_server.rbs +0 -3
  233. data/stdlib/socket/0/unix_socket.rbs +4 -2
  234. data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +1 -1
  235. data/stdlib/strscan/0/string_scanner.rbs +1265 -422
  236. data/stdlib/tempfile/0/tempfile.rbs +135 -28
  237. data/stdlib/time/0/time.rbs +48 -35
  238. data/stdlib/timeout/0/timeout.rbs +11 -8
  239. data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
  240. data/stdlib/tsort/0/tsort.rbs +0 -4
  241. data/stdlib/uri/0/common.rbs +28 -30
  242. data/stdlib/uri/0/ftp.rbs +1 -1
  243. data/stdlib/uri/0/generic.rbs +22 -18
  244. data/stdlib/uri/0/http.rbs +2 -2
  245. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  246. data/stdlib/zlib/0/buf_error.rbs +1 -70
  247. data/stdlib/zlib/0/data_error.rbs +1 -70
  248. data/stdlib/zlib/0/deflate.rbs +8 -72
  249. data/stdlib/zlib/0/error.rbs +1 -70
  250. data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
  251. data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
  252. data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
  253. data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
  254. data/stdlib/zlib/0/gzip_file.rbs +1 -71
  255. data/stdlib/zlib/0/gzip_reader.rbs +3 -74
  256. data/stdlib/zlib/0/gzip_writer.rbs +1 -70
  257. data/stdlib/zlib/0/inflate.rbs +4 -71
  258. data/stdlib/zlib/0/mem_error.rbs +1 -70
  259. data/stdlib/zlib/0/need_dict.rbs +1 -70
  260. data/stdlib/zlib/0/stream_end.rbs +1 -70
  261. data/stdlib/zlib/0/stream_error.rbs +1 -70
  262. data/stdlib/zlib/0/version_error.rbs +1 -70
  263. data/stdlib/zlib/0/zlib.rbs +0 -2
  264. data/stdlib/zlib/0/zstream.rbs +4 -72
  265. metadata +17 -13
  266. data/ext/rbs_extension/ruby_objs.c +0 -602
  267. data/ext/rbs_extension/ruby_objs.h +0 -51
  268. data/stdlib/minitest/0/manifest.yaml +0 -2
@@ -93,7 +93,7 @@ module RBS
93
93
  case
94
94
  when match = source.match(/(?<constant_name>[^#]+)#(?<method_name>.+)/)
95
95
  [
96
- TypeName(match[:constant_name] || raise),
96
+ TypeName.parse(match[:constant_name] || raise),
97
97
  [
98
98
  false,
99
99
  (match[:method_name] or raise).to_sym
@@ -101,7 +101,7 @@ module RBS
101
101
  ]
102
102
  when match = source.match(/(?<constant_name>[^#]+)\.(?<method_name>.+)/)
103
103
  [
104
- TypeName(match[:constant_name] || raise),
104
+ TypeName.parse(match[:constant_name] || raise),
105
105
  [
106
106
  true,
107
107
  (match[:method_name] or raise).to_sym
@@ -109,7 +109,7 @@ module RBS
109
109
  ]
110
110
  else
111
111
  [
112
- TypeName(source),
112
+ TypeName.parse(source),
113
113
  nil
114
114
  ]
115
115
  end
@@ -31,7 +31,7 @@ module RBS
31
31
  end
32
32
 
33
33
  def find_class(typename)
34
- classes = []
34
+ classes = [] #: Array[::RDoc::ClassModule]
35
35
 
36
36
  @stores.each do |store|
37
37
  if klass = store.find_class_or_module(typename.relative!.to_s)
@@ -70,7 +70,7 @@ module RBS
70
70
  def find_const(const_name)
71
71
  namespace =
72
72
  if const_name.namespace.empty?
73
- TypeName("::Object")
73
+ TypeName.parse("::Object")
74
74
  else
75
75
  const_name.namespace.to_type_name
76
76
  end
@@ -349,12 +349,14 @@ module RBS
349
349
  attr_reader :type
350
350
  attr_reader :location
351
351
  attr_reader :comment
352
+ attr_reader :annotations
352
353
 
353
- def initialize(name:, type:, location:, comment:)
354
+ def initialize(name:, type:, location:, comment:, annotations: [])
354
355
  @name = name
355
356
  @type = type
356
357
  @location = location
357
358
  @comment = comment
359
+ @annotations = annotations || []
358
360
  end
359
361
 
360
362
  def ==(other)
@@ -385,12 +387,14 @@ module RBS
385
387
  attr_reader :type
386
388
  attr_reader :location
387
389
  attr_reader :comment
390
+ attr_reader :annotations
388
391
 
389
- def initialize(name:, type:, location:, comment:)
392
+ def initialize(name:, type:, location:, comment:, annotations: [])
390
393
  @name = name
391
394
  @type = type
392
395
  @location = location
393
396
  @comment = comment
397
+ @annotations = annotations
394
398
  end
395
399
 
396
400
  def ==(other)
@@ -417,13 +421,14 @@ module RBS
417
421
  end
418
422
 
419
423
  class AliasDecl < Base
420
- attr_reader :new_name, :old_name, :location, :comment
424
+ attr_reader :new_name, :old_name, :location, :comment, :annotations
421
425
 
422
- def initialize(new_name:, old_name:, location:, comment:)
426
+ def initialize(new_name:, old_name:, location:, comment:, annotations: [])
423
427
  @new_name = new_name
424
428
  @old_name = old_name
425
429
  @location = location
426
430
  @comment = comment
431
+ @annotations = annotations
427
432
  end
428
433
 
429
434
  def ==(other)
@@ -34,6 +34,16 @@ module RBS
34
34
  end
35
35
  end
36
36
 
37
+ class ResolveTypeNames < Base
38
+ attr_reader :location
39
+
40
+ attr_reader :value
41
+
42
+ def initialize(value:, location:)
43
+ @value = value
44
+ @location = location
45
+ end
46
+ end
37
47
  end
38
48
  end
39
49
  end
@@ -30,6 +30,8 @@ module RBS
30
30
  end
31
31
 
32
32
  def sub(subst)
33
+ return self if subst.empty?
34
+
33
35
  update(method_type: self.method_type.sub(subst))
34
36
  end
35
37
 
@@ -5,13 +5,13 @@ module RBS
5
5
  class TypeParam
6
6
  attr_reader :name, :variance, :location, :upper_bound_type, :default_type
7
7
 
8
- def initialize(name:, variance:, upper_bound:, location:, default_type: nil)
8
+ def initialize(name:, variance:, upper_bound:, location:, default_type: nil, unchecked: false)
9
9
  @name = name
10
10
  @variance = variance
11
11
  @upper_bound_type = upper_bound
12
12
  @location = location
13
- @unchecked = false
14
13
  @default_type = default_type
14
+ @unchecked = unchecked
15
15
  end
16
16
 
17
17
  def upper_bound
@@ -56,16 +56,6 @@ module RBS
56
56
  }.to_json(state)
57
57
  end
58
58
 
59
- def rename(name)
60
- TypeParam.new(
61
- name: name,
62
- variance: variance,
63
- upper_bound: upper_bound_type,
64
- location: location,
65
- default_type: default_type
66
- ).unchecked!(unchecked?)
67
- end
68
-
69
59
  def map_type(&block)
70
60
  if b = upper_bound_type
71
61
  _upper_bound_type = yield(b)
data/lib/rbs/cli/diff.rb CHANGED
@@ -11,8 +11,8 @@ module RBS
11
11
  # @type var type_name: String?
12
12
  type_name = nil
13
13
  library_options = library_options
14
- before_path = []
15
- after_path = []
14
+ before_path = [] #: Array[String]
15
+ after_path = [] #: Array[String]
16
16
  detail = false
17
17
 
18
18
  opt = OptionParser.new do |o|
@@ -46,7 +46,7 @@ module RBS
46
46
  end
47
47
 
48
48
  @diff = RBS::Diff.new(
49
- type_name: TypeName(type_name).absolute!,
49
+ type_name: TypeName.parse(type_name).absolute!,
50
50
  library_options: library_options,
51
51
  after_path: after_path,
52
52
  before_path: before_path,
@@ -52,7 +52,7 @@ module RBS
52
52
  loader = options.loader()
53
53
  @env = Environment.from_loader(loader).resolve_type_names
54
54
  @builder = DefinitionBuilder.new(env: @env)
55
- @validator = Validator.new(env: @env, resolver: Resolver::TypeNameResolver.new(@env))
55
+ @validator = Validator.new(env: @env)
56
56
  exit_error = false
57
57
  limit = nil #: Integer?
58
58
  OptionParser.new do |opts|
@@ -196,6 +196,7 @@ EOU
196
196
  end
197
197
  InvalidTypeApplicationError.check!(type_name: member.name, params: params, args: member.args, location: member.location)
198
198
  when AST::Members::Var
199
+ @validator.validate_variable(member)
199
200
  void_type_context_validator(member.type)
200
201
  if member.is_a?(AST::Members::ClassVariable)
201
202
  no_self_type_validator(member.type)
data/lib/rbs/cli.rb CHANGED
@@ -288,7 +288,7 @@ EOU
288
288
  env = Environment.from_loader(loader).resolve_type_names
289
289
 
290
290
  builder = DefinitionBuilder::AncestorBuilder.new(env: env)
291
- type_name = TypeName(args[0]).absolute!
291
+ type_name = TypeName.parse(args[0]).absolute!
292
292
 
293
293
  case env.constant_entry(type_name)
294
294
  when Environment::ClassEntry, Environment::ModuleEntry, Environment::ClassAliasEntry, Environment::ModuleAliasEntry
@@ -353,7 +353,7 @@ EOU
353
353
  env = Environment.from_loader(loader).resolve_type_names
354
354
 
355
355
  builder = DefinitionBuilder.new(env: env)
356
- type_name = TypeName(args[0]).absolute!
356
+ type_name = TypeName.parse(args[0]).absolute!
357
357
 
358
358
  if env.module_name?(type_name)
359
359
  definition = case kind
@@ -406,7 +406,7 @@ EOU
406
406
  env = Environment.from_loader(loader).resolve_type_names
407
407
 
408
408
  builder = DefinitionBuilder.new(env: env)
409
- type_name = TypeName(args[0]).absolute!
409
+ type_name = TypeName.parse(args[0]).absolute!
410
410
  method_name = args[1].to_sym
411
411
 
412
412
  unless env.module_name?(type_name)
@@ -479,9 +479,9 @@ EOU
479
479
  builder = DefinitionBuilder.new(env: env)
480
480
  resolver = Resolver::ConstantResolver.new(builder: builder)
481
481
 
482
- resolver_context = context ? [nil, TypeName(context).absolute!] : nil #: Resolver::context
482
+ resolver_context = context ? [nil, TypeName.parse(context).absolute!] : nil #: Resolver::context
483
483
  stdout.puts "Context: #{context}"
484
- const_name = TypeName(args[0])
484
+ const_name = TypeName.parse(args[0])
485
485
  stdout.puts "Constant name: #{const_name}"
486
486
 
487
487
  if const_name.absolute?
@@ -554,11 +554,11 @@ EOU
554
554
  when "rbi", "rb"
555
555
  run_prototype_file(format, args)
556
556
  when "runtime"
557
- require_libs = []
558
- relative_libs = []
557
+ require_libs = [] #: Array[String]
558
+ relative_libs = [] #: Array[String]
559
559
  merge = false
560
560
  todo = false
561
- owners_included = []
561
+ owners_included = [] #: Array[Symbol]
562
562
  outline = false
563
563
  autoload = false
564
564
 
@@ -587,11 +587,11 @@ EOU
587
587
  merge = true
588
588
  end
589
589
  opts.on("--todo", "Generates only undefined methods compared to objects") do
590
- Warning.warn("Geneating prototypes with `--todo` option is experimental\n", category: :experimental)
590
+ Warning.warn("Generating prototypes with `--todo` option is experimental\n", category: :experimental)
591
591
  todo = true
592
592
  end
593
593
  opts.on("--method-owner CLASS", "Generate method prototypes if the owner of the method is [CLASS]") do |klass|
594
- owners_included << klass
594
+ owners_included << klass.to_sym
595
595
  end
596
596
  opts.on("--outline", "Generates only module/class/constant declaration (no method definition)") do
597
597
  outline = true
@@ -615,9 +615,9 @@ EOU
615
615
  ::Module.prepend(hook)
616
616
  ::Kernel.prepend(hook)
617
617
 
618
- arguments = []
618
+ arguments = [] #: Array[[Module, interned]]
619
619
  TracePoint.new(:call) do |tp|
620
- base = tp.self.kind_of?(Module) ? tp.self : Kernel
620
+ base = tp.self.kind_of?(Module) ? tp.self : Kernel #: Module
621
621
  name = (tp.binding or raise).local_variable_get(:name)
622
622
  arguments << [base, name]
623
623
  end.enable(target: hook.instance_method(:autoload), &block)
@@ -979,7 +979,7 @@ Options:
979
979
  end
980
980
 
981
981
  def test_opt options
982
- opts = []
982
+ opts = [] #: Array[String]
983
983
 
984
984
  opts.push(*options.repos.map {|dir| "--repo #{Shellwords.escape(dir)}"})
985
985
  opts.push(*options.dirs.map {|dir| "-I #{Shellwords.escape(dir)}"})
@@ -1056,7 +1056,7 @@ EOB
1056
1056
  require 'bundler'
1057
1057
 
1058
1058
  opts = collection_options(args)
1059
- params = {}
1059
+ params = {} #: Hash[Symbol, untyped]
1060
1060
  opts.order args.drop(1), into: params
1061
1061
  config_path = options.config_path or raise
1062
1062
  lock_path = Collection::Config.to_lockfile_path(config_path)
@@ -1155,7 +1155,7 @@ EOB
1155
1155
  # Generate RBS files from the codebase.
1156
1156
  $ rbs prototype rb lib/ > generated.rbs
1157
1157
 
1158
- # Write more descrictive types by hand.
1158
+ # Write more descriptive types by hand.
1159
1159
  $ $EDITOR handwritten.rbs
1160
1160
 
1161
1161
  # Remove hand-written method definitions from generated.rbs.
@@ -1163,7 +1163,7 @@ EOB
1163
1163
 
1164
1164
  Options:
1165
1165
  HELP
1166
- opts.on('-w', '--write', 'Overwrite files directry') { write_to_file = true }
1166
+ opts.on('-w', '--write', 'Overwrite files directory') { write_to_file = true }
1167
1167
  opts.on('--subtrahend=PATH', '') { |path| subtrahend_paths << path }
1168
1168
  opts.parse!(args)
1169
1169
  end
@@ -4,6 +4,18 @@ module RBS
4
4
  module Collection
5
5
  class Config
6
6
  class LockfileGenerator
7
+ ALUMNI_STDLIBS = {
8
+ "mutex_m" => ">= 0.3.0",
9
+ "abbrev" => nil,
10
+ "base64" => nil,
11
+ "bigdecimal" => nil,
12
+ "csv" => nil,
13
+ "minitest" => nil,
14
+ "net-smtp" => nil,
15
+ "nkf" => nil,
16
+ "observer" => nil,
17
+ }
18
+
7
19
  class GemfileLockMismatchError < StandardError
8
20
  def initialize(expected:, actual:)
9
21
  @expected = expected
@@ -58,9 +70,10 @@ module RBS
58
70
 
59
71
  def generate
60
72
  config.gems.each do |gem|
61
- if Sources::Stdlib.instance.has?(gem["name"], nil) || gem.dig("source", "type") == "stdlib"
73
+ case
74
+ when gem.dig("source", "type") == "stdlib"
62
75
  unless gem.fetch("ignore", false)
63
- assign_stdlib(name: gem["name"], from_gem: nil)
76
+ assign_stdlib(name: gem["name"])
64
77
  end
65
78
  else
66
79
  assign_gem(name: gem["name"], version: gem["version"])
@@ -113,6 +126,11 @@ module RBS
113
126
  find_source(name: name)
114
127
  end
115
128
 
129
+ if source.is_a?(Sources::Stdlib)
130
+ assign_stdlib(name: name)
131
+ return
132
+ end
133
+
116
134
  if source
117
135
  installed_version = version
118
136
  best_version = find_best_version(version: installed_version, versions: source.versions(name))
@@ -149,16 +167,48 @@ module RBS
149
167
  end
150
168
  end
151
169
 
152
- private def assign_stdlib(name:, from_gem:)
170
+ private def assign_stdlib(name:, from_gem: nil)
153
171
  return if lockfile.gems.key?(name)
154
172
 
155
173
  case name
156
- when 'rubygems', 'set'
157
- msg = "`#{name}` has been moved to core library, so it is always loaded. Remove explicit loading `#{name}`"
158
- msg << " from `#{from_gem}`" if from_gem
159
- RBS.logger.warn msg
160
-
174
+ when 'bigdecimal-math'
175
+ # The `bigdecimal-math` is never released as a gem.
176
+ # Therefore, `assign_gem` should not be called.
177
+ RBS.logger.info {
178
+ from = from_gem || "rbs_collection.yaml"
179
+ "`#{name}` is included in the RBS dependencies of `#{from}`, but the type definition as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies of `#{from}`."
180
+ }
181
+ source = find_source(name: name)
182
+ if source&.is_a?(Sources::Stdlib)
183
+ lockfile.gems[name] = { name: name, version: "0", source: source }
184
+ end
161
185
  return
186
+ when *ALUMNI_STDLIBS.keys
187
+ version = ALUMNI_STDLIBS.fetch(name)
188
+ if from_gem
189
+ # From `dependencies:` of a `manifest.yaml` of a gem
190
+ source = find_source(name: name) or raise
191
+ if source.is_a?(Sources::Stdlib) && version
192
+ RBS.logger.warn {
193
+ "`#{name}` is included in the RBS dependencies of `#{from_gem}`, but the type definition as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
194
+ }
195
+ else
196
+ RBS.logger.info {
197
+ "`#{name}` is included in the RBS dependencies of `#{from_gem}`, but the type definition as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies of `#{from_gem}`."
198
+ }
199
+ assign_gem(name: name, version: nil)
200
+ return
201
+ end
202
+ else
203
+ # From `gems:` of a `rbs_collection.yaml`
204
+ RBS.logger.warn {
205
+ if version
206
+ "`#{name}` as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
207
+ else
208
+ "`#{name}` as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies in your rbs_collection.yaml."
209
+ end
210
+ }
211
+ end
162
212
  end
163
213
 
164
214
  source = Sources::Stdlib.instance
@@ -66,13 +66,15 @@ module RBS
66
66
  def sources
67
67
  @sources ||= [
68
68
  Sources::Rubygems.instance,
69
- Sources::Stdlib.instance,
70
- *@data['sources'].map { |c| Sources.from_config_entry(c, base_directory: @config_path.dirname) }
69
+ *@data['sources'].map { |c| Sources.from_config_entry(c, base_directory: @config_path.dirname) },
70
+ Sources::Stdlib.instance
71
71
  ]
72
72
  end
73
73
 
74
74
  def gems
75
- @data['gems'] ||= []
75
+ @data['gems'] ||= (
76
+ [] #: Array[gem_entry]
77
+ )
76
78
  end
77
79
  end
78
80
  end
@@ -5,7 +5,7 @@ require 'singleton'
5
5
  module RBS
6
6
  module Collection
7
7
  module Sources
8
- # Signatures that are inclduded in gem package as sig/ directory.
8
+ # Signatures that are included in gem package as sig/ directory.
9
9
  class Rubygems
10
10
  include Base
11
11
  include Singleton
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
+ require 'fileutils'
4
5
 
5
6
  require_relative './cli/colored_io'
6
7
  require_relative './collection/sources'
@@ -6,18 +6,23 @@ module RBS
6
6
  attr_reader :parent_variable
7
7
  attr_reader :type
8
8
  attr_reader :declared_in
9
+ attr_reader :source
9
10
 
10
- def initialize(parent_variable:, type:, declared_in:)
11
+ def initialize(parent_variable:, type:, declared_in:, source:)
11
12
  @parent_variable = parent_variable
12
13
  @type = type
13
14
  @declared_in = declared_in
15
+ @source = source
14
16
  end
15
17
 
16
18
  def sub(s)
19
+ return self if s.empty?
20
+
17
21
  self.class.new(
18
22
  parent_variable: parent_variable,
19
23
  type: type.sub(s),
20
- declared_in: declared_in
24
+ declared_in: declared_in,
25
+ source: source
21
26
  )
22
27
  end
23
28
  end
@@ -28,12 +33,18 @@ module RBS
28
33
  attr_reader :member
29
34
  attr_reader :defined_in
30
35
  attr_reader :implemented_in
36
+ attr_reader :member_annotations
37
+ attr_reader :overload_annotations
38
+ attr_reader :annotations
31
39
 
32
- def initialize(type:, member:, defined_in:, implemented_in:)
40
+ def initialize(type:, member:, defined_in:, implemented_in:, overload_annotations: [])
33
41
  @type = type
34
42
  @member = member
35
43
  @defined_in = defined_in
36
44
  @implemented_in = implemented_in
45
+ @member_annotations = []
46
+ @overload_annotations = []
47
+ @annotations = []
37
48
  end
38
49
 
39
50
  def ==(other)
@@ -54,12 +65,11 @@ module RBS
54
65
  member.comment
55
66
  end
56
67
 
57
- def annotations
58
- member.annotations
59
- end
60
-
61
68
  def update(type: self.type, member: self.member, defined_in: self.defined_in, implemented_in: self.implemented_in)
62
- TypeDef.new(type: type, member: member, defined_in: defined_in, implemented_in: implemented_in)
69
+ TypeDef.new(type: type, member: member, defined_in: defined_in, implemented_in: implemented_in).tap do |type_def|
70
+ type_def.overload_annotations.replace(self.overload_annotations)
71
+ type_def.member_annotations.replace(self.member_annotations)
72
+ end
63
73
  end
64
74
 
65
75
  def overload?
@@ -70,20 +80,33 @@ module RBS
70
80
  false
71
81
  end
72
82
  end
83
+
84
+ def each_annotation(&block)
85
+ if block
86
+ member_annotations.each(&block)
87
+ overload_annotations.each(&block)
88
+ else
89
+ enum_for :each_annotation
90
+ end
91
+ end
73
92
  end
74
93
 
75
94
  attr_reader :super_method
76
95
  attr_reader :defs
77
96
  attr_reader :accessibility
78
97
  attr_reader :extra_annotations
98
+ attr_reader :annotations
79
99
  attr_reader :alias_of
100
+ attr_reader :alias_member
80
101
 
81
- def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:)
102
+ def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil)
82
103
  @super_method = super_method
83
104
  @defs = defs
84
105
  @accessibility = accessibility
85
- @extra_annotations = annotations
106
+ @extra_annotations = []
107
+ @annotations = []
86
108
  @alias_of = alias_of
109
+ @alias_member = alias_member
87
110
  end
88
111
 
89
112
  def ==(other)
@@ -92,7 +115,8 @@ module RBS
92
115
  other.defs == defs &&
93
116
  other.accessibility == accessibility &&
94
117
  other.annotations == annotations &&
95
- other.alias_of == alias_of
118
+ other.alias_of == alias_of &&
119
+ other.alias_member == alias_member
96
120
  end
97
121
 
98
122
  alias eql? ==
@@ -123,10 +147,6 @@ module RBS
123
147
  @comments ||= defs.map(&:comment).compact.uniq
124
148
  end
125
149
 
126
- def annotations
127
- @annotations ||= @extra_annotations + defs.flat_map {|d| d.annotations }
128
- end
129
-
130
150
  def members
131
151
  @members ||= defs.map(&:member).uniq
132
152
  end
@@ -140,49 +160,44 @@ module RBS
140
160
  end
141
161
 
142
162
  def sub(s)
143
- self.class.new(
163
+ return self if s.empty?
164
+
165
+ update(
144
166
  super_method: super_method&.sub(s),
145
- defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) },
146
- accessibility: @accessibility,
147
- alias_of: alias_of
167
+ defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) }
148
168
  )
149
169
  end
150
170
 
151
171
  def map_type(&block)
152
- self.class.new(
172
+ update(
153
173
  super_method: super_method&.map_type(&block),
154
- defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) },
155
- accessibility: @accessibility,
156
- alias_of: alias_of
174
+ defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) }
157
175
  )
158
176
  end
159
177
 
160
178
  def map_type_bound(&block)
161
- self.class.new(
179
+ update(
162
180
  super_method: super_method&.map_type_bound(&block),
163
- defs: defs.map {|defn| defn.update(type: defn.type.map_type_bound(&block)) },
164
- accessibility: @accessibility,
165
- alias_of: alias_of
181
+ defs: defs.map {|defn| defn.update(type: defn.type.map_type_bound(&block)) }
166
182
  )
167
183
  end
168
184
 
169
185
  def map_method_type(&block)
170
- self.class.new(
171
- super_method: super_method,
186
+ update(
172
187
  defs: defs.map {|defn| defn.update(type: yield(defn.type)) },
173
- accessibility: @accessibility,
174
- alias_of: alias_of
175
188
  )
176
189
  end
177
190
 
178
- def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations)
191
+ def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations, alias_member: self.alias_member)
179
192
  self.class.new(
180
193
  super_method: super_method,
181
194
  defs: defs,
182
195
  accessibility: accessibility,
183
196
  alias_of: alias_of,
184
- annotations: annotations
185
- )
197
+ alias_member: alias_member
198
+ ).tap do |method|
199
+ method.annotations.replace(annotations)
200
+ end
186
201
  end
187
202
  end
188
203
 
@@ -345,6 +360,8 @@ module RBS
345
360
  end
346
361
 
347
362
  def sub(s)
363
+ return self if s.empty?
364
+
348
365
  definition = self.class.new(type_name: type_name, self_type: _ = self_type.sub(s), ancestors: ancestors, entry: entry)
349
366
 
350
367
  definition.methods.merge!(methods.transform_values {|method| method.sub(s) })
@@ -209,7 +209,7 @@ module RBS
209
209
  super_args = super_class.args
210
210
  else
211
211
  super_name = BuiltinNames::Object.name
212
- super_args = []
212
+ super_args = [] #: Array[Types::t]
213
213
  end
214
214
 
215
215
  super_name = env.normalize_module_name(super_name)
@@ -217,6 +217,7 @@ module RBS
217
217
  NoSuperclassFoundError.check!(super_name, env: env, location: primary.decl.location)
218
218
  if super_class
219
219
  InheritModuleError.check!(super_class, env: env)
220
+ InvalidTypeApplicationError.check2!(type_name: super_class.name, args: super_class.args, env: env, location: super_class.location)
220
221
  end
221
222
 
222
223
  super_entry = env.normalized_class_entry(super_name) or raise
@@ -243,6 +244,7 @@ module RBS
243
244
  else
244
245
  entry.self_types.each do |module_self|
245
246
  NoSelfTypeFoundError.check!(module_self, env: env)
247
+ InvalidTypeApplicationError.check2!(type_name: module_self.name, args: module_self.args, env: env, location: module_self.location)
246
248
 
247
249
  module_name = module_self.name
248
250
  if module_name.class?
@@ -525,7 +527,7 @@ module RBS
525
527
 
526
528
  one_ancestors = one_singleton_ancestors(type_name)
527
529
 
528
- ancestors = []
530
+ ancestors = [] #: Array[Definition::Ancestor::t]
529
531
 
530
532
  case super_class = one_ancestors.super_class
531
533
  when Definition::Ancestor::Instance
@@ -581,7 +583,7 @@ module RBS
581
583
  building_ancestors.push self_ancestor
582
584
 
583
585
  one_ancestors = one_interface_ancestors(type_name)
584
- ancestors = []
586
+ ancestors = [] #: Array[Definition::Ancestor::t]
585
587
 
586
588
  included_interfaces = one_ancestors.included_interfaces or raise
587
589
  included_interfaces.each do |a|