rbs 3.7.0 → 3.8.0.pre.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.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +7 -7
  4. data/CHANGELOG.md +52 -0
  5. data/core/array.rbs +1743 -1580
  6. data/core/basic_object.rbs +38 -35
  7. data/core/comparable.rbs +1 -1
  8. data/core/complex.rbs +165 -93
  9. data/core/data.rbs +1 -1
  10. data/core/dir.rbs +1 -17
  11. data/core/encoding.rbs +12 -6
  12. data/core/enumerable.rbs +270 -266
  13. data/core/enumerator.rbs +0 -2
  14. data/core/env.rbs +1 -1
  15. data/core/errno.rbs +33 -16
  16. data/core/errors.rbs +2 -2
  17. data/core/exception.rbs +236 -170
  18. data/core/fiber.rbs +3 -2
  19. data/core/file.rbs +32 -74
  20. data/core/float.rbs +125 -72
  21. data/core/gc.rbs +138 -40
  22. data/core/hash.rbs +120 -141
  23. data/core/integer.rbs +79 -50
  24. data/core/io/buffer.rbs +49 -43
  25. data/core/io.rbs +97 -144
  26. data/core/kernel.rbs +290 -200
  27. data/core/match_data.rbs +76 -2
  28. data/core/math.rbs +0 -36
  29. data/core/module.rbs +28 -23
  30. data/core/nil_class.rbs +0 -3
  31. data/core/numeric.rbs +100 -103
  32. data/core/object.rbs +0 -4
  33. data/core/object_space/weak_key_map.rbs +3 -4
  34. data/core/object_space.rbs +3 -3
  35. data/core/proc.rbs +0 -2
  36. data/core/process.rbs +109 -57
  37. data/core/ractor.rbs +37 -4
  38. data/core/range.rbs +114 -87
  39. data/core/rational.rbs +0 -2
  40. data/core/rbs/unnamed/argf.rbs +234 -33
  41. data/core/rbs/unnamed/env_class.rbs +35 -53
  42. data/core/rbs/unnamed/random.rbs +1 -2
  43. data/core/regexp.rbs +4 -52
  44. data/core/ruby_vm.rbs +88 -9
  45. data/core/rubygems/config_file.rbs +3 -0
  46. data/core/rubygems/errors.rbs +0 -5
  47. data/core/rubygems/platform.rbs +0 -9
  48. data/core/rubygems/rubygems.rbs +0 -5
  49. data/core/rubygems/version.rbs +6 -6
  50. data/core/set.rbs +3 -15
  51. data/core/string.rbs +130 -136
  52. data/core/struct.rbs +6 -18
  53. data/core/symbol.rbs +14 -21
  54. data/core/thread.rbs +32 -35
  55. data/core/time.rbs +127 -50
  56. data/core/trace_point.rbs +16 -0
  57. data/core/true_class.rbs +0 -1
  58. data/core/warning.rbs +9 -2
  59. data/docs/architecture.md +1 -1
  60. data/docs/syntax.md +1 -1
  61. data/ext/rbs_extension/location.c +29 -19
  62. data/ext/rbs_extension/parser.c +267 -292
  63. data/ext/rbs_extension/parserstate.c +56 -22
  64. data/lib/rbs/annotate/annotations.rb +3 -3
  65. data/lib/rbs/annotate/rdoc_source.rb +2 -2
  66. data/lib/rbs/cli/diff.rb +3 -3
  67. data/lib/rbs/cli/validate.rb +1 -1
  68. data/lib/rbs/cli.rb +13 -13
  69. data/lib/rbs/collection/config.rb +3 -1
  70. data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
  71. data/lib/rbs/environment_loader.rb +1 -1
  72. data/lib/rbs/namespace.rb +1 -0
  73. data/lib/rbs/parser_aux.rb +2 -2
  74. data/lib/rbs/prototype/rb.rb +11 -8
  75. data/lib/rbs/prototype/rbi.rb +9 -5
  76. data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
  77. data/lib/rbs/prototype/runtime.rb +4 -5
  78. data/lib/rbs/type_name.rb +14 -9
  79. data/lib/rbs/unit_test/type_assertions.rb +2 -2
  80. data/lib/rbs/validator.rb +3 -1
  81. data/lib/rbs/version.rb +1 -1
  82. data/lib/rdoc_plugin/parser.rb +2 -2
  83. data/rbs.gemspec +4 -0
  84. data/sig/ancestor_graph.rbs +4 -4
  85. data/sig/namespace.rbs +2 -3
  86. data/sig/resolver/constant_resolver.rbs +2 -2
  87. data/sig/resolver/context.rbs +1 -1
  88. data/sig/type_alias_regularity.rbs +5 -5
  89. data/sig/typename.rbs +8 -5
  90. data/sig/use_map.rbs +1 -1
  91. data/sig/validator.rbs +2 -2
  92. data/stdlib/base64/0/base64.rbs +0 -9
  93. data/stdlib/benchmark/0/benchmark.rbs +11 -2
  94. data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
  95. data/stdlib/cgi/0/core.rbs +47 -0
  96. data/stdlib/coverage/0/coverage.rbs +0 -3
  97. data/stdlib/csv/0/csv.rbs +18 -58
  98. data/stdlib/date/0/date.rbs +4 -19
  99. data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
  100. data/stdlib/digest/0/digest.rbs +25 -2
  101. data/stdlib/erb/0/erb.rbs +0 -1
  102. data/stdlib/etc/0/etc.rbs +51 -34
  103. data/stdlib/fileutils/0/fileutils.rbs +3 -44
  104. data/stdlib/io-console/0/io-console.rbs +69 -15
  105. data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
  106. data/stdlib/json/0/json.rbs +56 -71
  107. data/stdlib/logger/0/log_device.rbs +1 -1
  108. data/stdlib/logger/0/logger.rbs +3 -18
  109. data/stdlib/net-http/0/net-http.rbs +19 -77
  110. data/stdlib/nkf/0/nkf.rbs +30 -0
  111. data/stdlib/objspace/0/objspace.rbs +1 -2
  112. data/stdlib/observable/0/observable.rbs +1 -1
  113. data/stdlib/open-uri/0/open-uri.rbs +52 -0
  114. data/stdlib/open3/0/open3.rbs +0 -8
  115. data/stdlib/openssl/0/openssl.rbs +136 -69
  116. data/stdlib/optparse/0/optparse.rbs +58 -18
  117. data/stdlib/pathname/0/pathname.rbs +2 -8
  118. data/stdlib/pp/0/pp.rbs +3 -1
  119. data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
  120. data/stdlib/pstore/0/pstore.rbs +0 -6
  121. data/stdlib/psych/0/psych.rbs +15 -4
  122. data/stdlib/pty/0/pty.rbs +46 -4
  123. data/stdlib/rdoc/0/code_object.rbs +0 -4
  124. data/stdlib/rdoc/0/markup.rbs +10 -12
  125. data/stdlib/rdoc/0/rdoc.rbs +1 -2
  126. data/stdlib/resolv/0/resolv.rbs +8 -3
  127. data/stdlib/ripper/0/ripper.rbs +0 -2
  128. data/stdlib/securerandom/0/securerandom.rbs +0 -2
  129. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  130. data/stdlib/singleton/0/singleton.rbs +0 -1
  131. data/stdlib/socket/0/addrinfo.rbs +0 -1
  132. data/stdlib/socket/0/basic_socket.rbs +0 -5
  133. data/stdlib/socket/0/socket.rbs +49 -25
  134. data/stdlib/socket/0/tcp_server.rbs +0 -3
  135. data/stdlib/socket/0/tcp_socket.rbs +58 -3
  136. data/stdlib/socket/0/udp_socket.rbs +0 -1
  137. data/stdlib/socket/0/unix_server.rbs +0 -3
  138. data/stdlib/strscan/0/string_scanner.rbs +1265 -422
  139. data/stdlib/tempfile/0/tempfile.rbs +135 -28
  140. data/stdlib/time/0/time.rbs +48 -35
  141. data/stdlib/timeout/0/timeout.rbs +11 -8
  142. data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
  143. data/stdlib/tsort/0/tsort.rbs +0 -4
  144. data/stdlib/uri/0/common.rbs +11 -30
  145. data/stdlib/uri/0/ftp.rbs +1 -1
  146. data/stdlib/uri/0/generic.rbs +22 -18
  147. data/stdlib/uri/0/http.rbs +2 -2
  148. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  149. data/stdlib/zlib/0/buf_error.rbs +1 -70
  150. data/stdlib/zlib/0/data_error.rbs +1 -70
  151. data/stdlib/zlib/0/deflate.rbs +8 -72
  152. data/stdlib/zlib/0/error.rbs +1 -70
  153. data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
  154. data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
  155. data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
  156. data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
  157. data/stdlib/zlib/0/gzip_file.rbs +1 -71
  158. data/stdlib/zlib/0/gzip_reader.rbs +3 -74
  159. data/stdlib/zlib/0/gzip_writer.rbs +1 -70
  160. data/stdlib/zlib/0/inflate.rbs +4 -71
  161. data/stdlib/zlib/0/mem_error.rbs +1 -70
  162. data/stdlib/zlib/0/need_dict.rbs +1 -70
  163. data/stdlib/zlib/0/stream_end.rbs +1 -70
  164. data/stdlib/zlib/0/stream_error.rbs +1 -70
  165. data/stdlib/zlib/0/version_error.rbs +1 -70
  166. data/stdlib/zlib/0/zlib.rbs +0 -2
  167. data/stdlib/zlib/0/zstream.rbs +4 -72
  168. metadata +4 -6
@@ -4,16 +4,26 @@
4
4
 
5
5
  id_table *alloc_empty_table(void) {
6
6
  id_table *table = malloc(sizeof(id_table));
7
- table->size = 10;
8
- table->count = 0;
9
- table->ids = calloc(10, sizeof(ID));
7
+
8
+ *table = (id_table) {
9
+ .size = 10,
10
+ .count = 0,
11
+ .ids = calloc(10, sizeof(ID)),
12
+ .next = NULL,
13
+ };
10
14
 
11
15
  return table;
12
16
  }
13
17
 
14
18
  id_table *alloc_reset_table(void) {
15
19
  id_table *table = malloc(sizeof(id_table));
16
- table->size = 0;
20
+
21
+ *table = (id_table) {
22
+ .size = 0,
23
+ .count = 0,
24
+ .ids = NULL,
25
+ .next = NULL,
26
+ };
17
27
 
18
28
  return table;
19
29
  }
@@ -182,15 +192,18 @@ VALUE get_comment(parserstate *state, int subject_line) {
182
192
  }
183
193
 
184
194
  comment *alloc_comment(token comment_token, comment *last_comment) {
185
- comment *new_comment = calloc(1, sizeof(comment));
195
+ comment *new_comment = malloc(sizeof(comment));
186
196
 
187
- new_comment->next_comment = last_comment;
197
+ *new_comment = (comment) {
198
+ .start = comment_token.range.start,
199
+ .end = comment_token.range.end,
188
200
 
189
- new_comment->start = comment_token.range.start;
190
- new_comment->end = comment_token.range.end;
201
+ .line_size = 0,
202
+ .line_count = 0,
203
+ .tokens = NULL,
191
204
 
192
- new_comment->line_size = 0;
193
- new_comment->line_count = 0;
205
+ .next_comment = last_comment,
206
+ };
194
207
 
195
208
  comment_insert_new_line(new_comment, comment_token);
196
209
 
@@ -279,11 +292,25 @@ lexstate *alloc_lexer(VALUE string, int start_pos, int end_pos) {
279
292
  rb_raise(rb_eArgError, "negative position range: %d...%d", start_pos, end_pos);
280
293
  }
281
294
 
282
- lexstate *lexer = calloc(1, sizeof(lexstate));
283
- lexer->string = string;
284
- lexer->current.line = 1;
285
- lexer->start_pos = start_pos;
286
- lexer->end_pos = end_pos;
295
+ lexstate *lexer = malloc(sizeof(lexstate));
296
+
297
+ position start_position = (position) {
298
+ .byte_pos = 0,
299
+ .char_pos = 0,
300
+ .line = 1,
301
+ .column = 0,
302
+ };
303
+
304
+ *lexer = (lexstate) {
305
+ .string = string,
306
+ .start_pos = start_pos,
307
+ .end_pos = end_pos,
308
+ .current = start_position,
309
+ .start = { 0 },
310
+ .first_token_of_line = false,
311
+ .last_char = 0,
312
+ };
313
+
287
314
  skipn(lexer, start_pos);
288
315
  lexer->start = lexer->current;
289
316
  lexer->first_token_of_line = lexer->current.column == 0;
@@ -292,13 +319,20 @@ lexstate *alloc_lexer(VALUE string, int start_pos, int end_pos) {
292
319
  }
293
320
 
294
321
  parserstate *alloc_parser(VALUE buffer, lexstate *lexer, int start_pos, int end_pos, VALUE variables) {
295
- parserstate *parser = calloc(1, sizeof(parserstate));
296
- parser->lexstate = lexer;
297
- parser->buffer = buffer;
298
- parser->current_token = NullToken;
299
- parser->next_token = NullToken;
300
- parser->next_token2 = NullToken;
301
- parser->next_token3 = NullToken;
322
+ parserstate *parser = malloc(sizeof(parserstate));
323
+
324
+ *parser = (parserstate) {
325
+ .lexstate = lexer,
326
+
327
+ .current_token = NullToken,
328
+ .next_token = NullToken,
329
+ .next_token2 = NullToken,
330
+ .next_token3 = NullToken,
331
+ .buffer = buffer,
332
+
333
+ .vars = NULL,
334
+ .last_comment = NULL,
335
+ };
302
336
 
303
337
  parser_advance(parser);
304
338
  parser_advance(parser);
@@ -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
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|
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
 
@@ -591,7 +591,7 @@ EOU
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)
@@ -72,7 +72,9 @@ module RBS
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
@@ -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)
@@ -525,7 +525,7 @@ module RBS
525
525
 
526
526
  one_ancestors = one_singleton_ancestors(type_name)
527
527
 
528
- ancestors = []
528
+ ancestors = [] #: Array[Definition::Ancestor::t]
529
529
 
530
530
  case super_class = one_ancestors.super_class
531
531
  when Definition::Ancestor::Instance
@@ -581,7 +581,7 @@ module RBS
581
581
  building_ancestors.push self_ancestor
582
582
 
583
583
  one_ancestors = one_interface_ancestors(type_name)
584
- ancestors = []
584
+ ancestors = [] #: Array[Definition::Ancestor::t]
585
585
 
586
586
  included_interfaces = one_ancestors.included_interfaces or raise
587
587
  included_interfaces.each do |a|
@@ -26,7 +26,7 @@ module RBS
26
26
  DEFAULT_CORE_ROOT = Pathname(_ = __dir__) + "../../core"
27
27
 
28
28
  def self.gem_sig_path(name, version)
29
- requirements = []
29
+ requirements = [] #: Array[String]
30
30
  requirements << version if version
31
31
  spec = Gem::Specification.find_by_name(name, *requirements)
32
32
  path = Pathname(spec.gem_dir) + "sig"
data/lib/rbs/namespace.rb CHANGED
@@ -119,6 +119,7 @@ end
119
119
 
120
120
  module Kernel
121
121
  def Namespace(name)
122
+ warn "Kernel#Namespace() is deprecated. Use RBS::Namespace.parse instead.", category: :deprecated
122
123
  RBS::Namespace.parse(name)
123
124
  end
124
125
  end
@@ -70,8 +70,8 @@ module RBS
70
70
  untyped
71
71
  true
72
72
  false
73
- ).each_with_object({}) do |keyword, hash|
74
- hash[keyword] = nil
73
+ ).each_with_object({}) do |keyword, hash| #$ Hash[String, bot]
74
+ hash[keyword] = _ = nil
75
75
  end
76
76
  end
77
77
  end
@@ -75,8 +75,8 @@ module RBS
75
75
  def parse(string)
76
76
  # @type var comments: Hash[Integer, AST::Comment]
77
77
  comments = Ripper.lex(string).yield_self do |tokens|
78
- code_lines = {}
79
- tokens.each.with_object({}) do |token, hash|
78
+ code_lines = {} #: Hash[Integer, bool]
79
+ tokens.each.with_object({}) do |token, hash| #$ Hash[Integer, AST::Comment]
80
80
  case token[1]
81
81
  when :on_sp, :on_ignored_nl
82
82
  # skip
@@ -643,11 +643,11 @@ module RBS
643
643
  children = list.children
644
644
  children.pop
645
645
  else
646
- children = []
646
+ children = [] #: Array[untyped]
647
647
  end
648
648
 
649
- key_types = []
650
- value_types = []
649
+ key_types = [] #: Array[Types::t]
650
+ value_types = [] #: Array[Types::t]
651
651
  children.each_slice(2) do |k, v|
652
652
  if k
653
653
  key_types << literal_to_type(k)
@@ -659,7 +659,10 @@ module RBS
659
659
  end
660
660
 
661
661
  if !key_types.empty? && key_types.all? { |t| t.is_a?(Types::Literal) }
662
- fields = key_types.map { |t| t.literal }.zip(value_types).to_h
662
+ fields = key_types.map {|t|
663
+ t.is_a?(Types::Literal) or raise
664
+ t.literal
665
+ }.zip(value_types).to_h #: Hash[Types::Literal::literal, Types::t]
663
666
  Types::Record.new(fields: fields, location: nil)
664
667
  else
665
668
  key_type = types_to_union_type(key_types)
@@ -719,9 +722,9 @@ module RBS
719
722
  when :FLOAT
720
723
  BuiltinNames::Float.instance_type
721
724
  when :RATIONAL
722
- Types::ClassInstance.new(name: TypeName("::Rational"), args: [], location: nil)
725
+ Types::ClassInstance.new(name: TypeName.parse("::Rational"), args: [], location: nil)
723
726
  when :IMAGINARY
724
- Types::ClassInstance.new(name: TypeName("::Complex"), args: [], location: nil)
727
+ Types::ClassInstance.new(name: TypeName.parse("::Complex"), args: [], location: nil)
725
728
  when :LIT
726
729
  case node.children[0]
727
730
  when Symbol
@@ -17,9 +17,7 @@ module RBS
17
17
 
18
18
  def parse(string)
19
19
  comments = Ripper.lex(string).yield_self do |tokens|
20
- tokens.each.with_object({}) do |token, hash|
21
- # @type var hash: Hash[Integer, AST::Comment]
22
-
20
+ tokens.each.with_object({}) do |token, hash| #$ Hash[Integer, AST::Comment]
23
21
  if token[1] == :on_comment
24
22
  line = token[0][0]
25
23
  body = token[2][2..-1] or raise
@@ -325,11 +323,17 @@ module RBS
325
323
  end
326
324
  end
327
325
  when :type_parameters
328
- type_params = []
326
+ type_params = [] #: Array[AST::TypeParam]
329
327
 
330
328
  each_arg args do |node|
331
329
  if name = symbol_literal_node?(node)
332
- type_params << name
330
+ type_params << AST::TypeParam.new(
331
+ name: name,
332
+ variance: :invariant,
333
+ upper_bound: nil,
334
+ location: nil,
335
+ default_type: nil
336
+ )
333
337
  end
334
338
  end
335
339
 
@@ -80,7 +80,9 @@ module RBS
80
80
  kind: :instance,
81
81
  location: nil,
82
82
  comment: nil,
83
- annotations: []
83
+ annotations: (
84
+ [] #: Array[AST::Annotation]
85
+ )
84
86
  )
85
87
  end
86
88
  end
@@ -100,7 +102,7 @@ module RBS
100
102
  CAN_CALL_KEYWORD_INIT_P = Struct.new(:tmp).respond_to?(:keyword_init?)
101
103
 
102
104
  def build_super_class
103
- AST::Declarations::Class::Super.new(name: TypeName("::Struct"), args: [untyped], location: nil)
105
+ AST::Declarations::Class::Super.new(name: TypeName.parse("::Struct"), args: [untyped], location: nil)
104
106
  end
105
107
 
106
108
  def add_decl_members(decl)
@@ -114,7 +116,7 @@ module RBS
114
116
  # | (?foo: untyped, ?bar: untyped) -> instance
115
117
  def build_s_new
116
118
  [:new, :[]].map do |name|
117
- new_overloads = []
119
+ new_overloads = [] #: Array[AST::Members::MethodDefinition::Overload]
118
120
 
119
121
  if CAN_CALL_KEYWORD_INIT_P
120
122
  case @target_class.keyword_init?
@@ -221,7 +223,7 @@ module RBS
221
223
  private
222
224
 
223
225
  def build_super_class
224
- AST::Declarations::Class::Super.new(name: TypeName("::Data"), args: [], location: nil)
226
+ AST::Declarations::Class::Super.new(name: TypeName.parse("::Data"), args: [], location: nil)
225
227
  end
226
228
 
227
229
  def add_decl_members(decl)
@@ -234,7 +236,7 @@ module RBS
234
236
  # | (foo: untyped, bar: untyped) -> instance
235
237
  def build_s_new
236
238
  [:new, :[]].map do |name|
237
- new_overloads = []
239
+ new_overloads = [] #: Array[AST::Members::MethodDefinition::Overload]
238
240
 
239
241
  new_overloads << AST::Members::MethodDefinition::Overload.new(
240
242
  annotations: [],
@@ -48,7 +48,8 @@ module RBS
48
48
 
49
49
  def mixin_decls(type_name)
50
50
  type_name_absolute = type_name.absolute!
51
- (@mixin_decls_cache ||= {}).fetch(type_name_absolute) do
51
+ @mixin_decls_cache ||= {} #: Hash[TypeName, Array[AST::Members::Mixin]]
52
+ @mixin_decls_cache.fetch(type_name_absolute) do
52
53
  @mixin_decls_cache[type_name_absolute] = @builder.env.class_decls[type_name_absolute].decls.flat_map do |d|
53
54
  d.decl.members.select { |m| m.kind_of?(AST::Members::Mixin) }
54
55
  end
@@ -448,9 +449,9 @@ module RBS
448
449
  location: nil
449
450
  )
450
451
  when ARGF
451
- Types::ClassInstance.new(name: TypeName("::RBS::Unnamed::ARGFClass"), args: [], location: nil)
452
+ Types::ClassInstance.new(name: TypeName.parse("::RBS::Unnamed::ARGFClass"), args: [], location: nil)
452
453
  when ENV
453
- Types::ClassInstance.new(name: TypeName("::RBS::Unnamed::ENVClass"), args: [], location: nil)
454
+ Types::ClassInstance.new(name: TypeName.parse("::RBS::Unnamed::ENVClass"), args: [], location: nil)
454
455
  else
455
456
  value_type_name = to_type_name(const_name!(Reflection.object_class(value)), full_name: true).absolute!
456
457
  args = type_args(value_type_name)
@@ -648,8 +649,6 @@ module RBS
648
649
  end
649
650
 
650
651
  def block_from_ast_of(method)
651
- return nil if RUBY_VERSION < '3.1'
652
-
653
652
  begin
654
653
  ast = RubyVM::AbstractSyntaxTree.of(method)
655
654
  rescue ArgumentError
data/lib/rbs/type_name.rb CHANGED
@@ -86,19 +86,24 @@ module RBS
86
86
  )
87
87
  end
88
88
  end
89
+
90
+ def self.parse(string)
91
+ absolute = string.start_with?("::")
92
+
93
+ *path, name = string.delete_prefix("::").split("::").map(&:to_sym)
94
+ raise unless name
95
+
96
+ TypeName.new(
97
+ name: name,
98
+ namespace: RBS::Namespace.new(path: path, absolute: absolute)
99
+ )
100
+ end
89
101
  end
90
102
  end
91
103
 
92
104
  module Kernel
93
105
  def TypeName(string)
94
- absolute = string.start_with?("::")
95
-
96
- *path, name = string.delete_prefix("::").split("::").map(&:to_sym)
97
- raise unless name
98
-
99
- RBS::TypeName.new(
100
- name: name,
101
- namespace: RBS::Namespace.new(path: path, absolute: absolute)
102
- )
106
+ warn "Kernel#TypeName() is deprecated. Use RBS::TypeName.parse instead.", category: :deprecated
107
+ RBS::TypeName.parse(string)
103
108
  end
104
109
  end
@@ -15,7 +15,7 @@ module RBS
15
15
  @target = nil
16
16
  end
17
17
 
18
- @@env_cache = {}
18
+ @@env_cache = {} #: Hash[Array[String], RBS::Environment]
19
19
 
20
20
  def env
21
21
  @env = @@env_cache[@libs] ||=
@@ -271,7 +271,7 @@ module RBS
271
271
 
272
272
  assert typecheck.value(constant, value_type), "`#{constant_name}` (#{constant.inspect}) must be compatible with given type `#{value_type}`"
273
273
 
274
- type_name = TypeName(constant_name).absolute!
274
+ type_name = TypeName.parse(constant_name).absolute!
275
275
  definition = env.constant_entry(type_name)
276
276
  assert definition, "Cannot find RBS type definition of `#{constant_name}`"
277
277
 
data/lib/rbs/validator.rb CHANGED
@@ -6,13 +6,15 @@ module RBS
6
6
  attr_reader :resolver
7
7
  attr_reader :definition_builder
8
8
 
9
- def initialize(env:, resolver:)
9
+ def initialize(env:, resolver: nil)
10
10
  @env = env
11
11
  @resolver = resolver
12
12
  @definition_builder = DefinitionBuilder.new(env: env)
13
13
  end
14
14
 
15
15
  def absolute_type(type, context:, &block)
16
+ return type unless resolver
17
+
16
18
  type.map_type_name do |type_name, _, type|
17
19
  resolver.resolve(type_name, context: context) || (block ? yield(type) : type_name)
18
20
  end
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "3.7.0"
4
+ VERSION = "3.8.0.pre.1"
5
5
  end
@@ -108,7 +108,7 @@ module RBS
108
108
 
109
109
  def parse_include_decl(decl:, context:, outer_name: nil)
110
110
  name = decl.name.to_s
111
- outer_names = outer_name ? outer_name.to_s.split("::") : []
111
+ outer_names = outer_name ? outer_name.to_s.split("::") : [] #: Array[String]
112
112
  qualified_name = ''
113
113
  outer_names.each do |namespace|
114
114
  qualified_name += namespace
@@ -124,7 +124,7 @@ module RBS
124
124
 
125
125
  def parse_extend_decl(decl:, context:, outer_name: nil)
126
126
  name = decl.name.to_s
127
- outer_names = outer_name ? outer_name.to_s.split("::") : []
127
+ outer_names = outer_name ? outer_name.to_s.split("::") : [] #: Array[String]
128
128
  qualified_name = ''
129
129
  outer_names.each do |namespace|
130
130
  qualified_name += namespace
data/rbs.gemspec CHANGED
@@ -37,6 +37,10 @@ Gem::Specification.new do |spec|
37
37
  end
38
38
  spec.extensions = %w{ext/rbs_extension/extconf.rb}
39
39
 
40
+ if false
41
+ spec.required_ruby_version = ">= 3.3"
42
+ end
43
+
40
44
  spec.bindir = "exe"
41
45
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
42
46
  spec.require_paths = ["lib"]
@@ -4,11 +4,11 @@ module RBS
4
4
  # ```ruby
5
5
  # graph = AncestorGraph.new(env: env, ancestor_builder: ancestor_builder)
6
6
  #
7
- # graph.each_parent(AncestorGraph::InstanceNode.new(type_name: TypeName("::Object")))
8
- # graph.each_ancestor(AncestorGraph::InstanceNode.new(type_name: TypeName("::Object")))
7
+ # graph.each_parent(AncestorGraph::InstanceNode.new(type_name: TypeName.parse("::Object")))
8
+ # graph.each_ancestor(AncestorGraph::InstanceNode.new(type_name: TypeName.parse("::Object")))
9
9
  #
10
- # graph.each_child(AncestorGraph::InstanceNode.new(type_name: TypeName("::Object")))
11
- # graph.each_descendant(AncestorGraph::InstanceNode.new(type_name: TypeName("::Object")))
10
+ # graph.each_child(AncestorGraph::InstanceNode.new(type_name: TypeName.parse("::Object")))
11
+ # graph.each_descendant(AncestorGraph::InstanceNode.new(type_name: TypeName.parse("::Object")))
12
12
  # ```
13
13
  #
14
14
  # Note that the class works for class/module declarations.
data/sig/namespace.rbs CHANGED
@@ -141,7 +141,6 @@ module RBS
141
141
  end
142
142
 
143
143
  module Kernel
144
- # Parses given string and returns Namespace.
145
- #
146
- def Namespace: (String) -> RBS::Namespace
144
+ # Deprecated: Use `RBS::Namespace.parse` instead
145
+ %a{steep:deprecated} def Namespace: (String) -> RBS::Namespace
147
146
  end
@@ -6,8 +6,8 @@ module RBS
6
6
  # ```rb
7
7
  # table = RBS::ConstantResolver::Table.new(env)
8
8
  #
9
- # table.children(TypeName("::Object")) # -> { ... } Returns a hash of name and constants.
10
- # table.children(TypeName("::File::PATH_SEPARATOR")) # -> nil Returns nil because the constant is not a module.
9
+ # table.children(TypeName.parse("::Object")) # -> { ... } Returns a hash of name and constants.
10
+ # table.children(TypeName.parse("::File::PATH_SEPARATOR")) # -> nil Returns nil because the constant is not a module.
11
11
  #
12
12
  # table.toplevel # -> { ... } Returns a hash of top level constants.
13
13
  # ```