rbs 2.0.0 → 2.2.2

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 (208) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +34 -0
  3. data/.github/workflows/ruby.yml +5 -0
  4. data/CHANGELOG.md +82 -0
  5. data/README.md +6 -1
  6. data/Rakefile +56 -21
  7. data/core/array.rbs +2866 -1086
  8. data/core/basic_object.rbs +150 -30
  9. data/core/binding.rbs +33 -0
  10. data/core/builtin.rbs +4 -4
  11. data/core/class.rbs +43 -5
  12. data/core/comparable.rbs +57 -0
  13. data/core/complex.rbs +170 -4
  14. data/core/constants.rbs +51 -0
  15. data/core/deprecated.rbs +7 -0
  16. data/core/dir.rbs +305 -20
  17. data/core/encoding.rbs +1214 -77
  18. data/core/enumerable.rbs +2173 -234
  19. data/core/enumerator.rbs +448 -182
  20. data/core/env.rbs +448 -1
  21. data/core/errno.rbs +1 -10
  22. data/core/errors.rbs +152 -2
  23. data/core/exception.rbs +201 -127
  24. data/core/false_class.rbs +27 -0
  25. data/core/fiber.rbs +118 -37
  26. data/core/fiber_error.rbs +8 -9
  27. data/core/file.rbs +1060 -142
  28. data/core/file_test.rbs +287 -32
  29. data/core/float.rbs +776 -300
  30. data/core/gc.rbs +185 -34
  31. data/core/global_variables.rbs +5 -1
  32. data/core/hash.rbs +1582 -649
  33. data/core/integer.rbs +974 -204
  34. data/core/io/buffer.rbs +710 -0
  35. data/core/io/wait.rbs +29 -8
  36. data/core/io.rbs +2438 -417
  37. data/core/kernel.rbs +2319 -318
  38. data/core/marshal.rbs +37 -2
  39. data/core/match_data.rbs +123 -6
  40. data/core/math.rbs +126 -6
  41. data/core/method.rbs +226 -102
  42. data/core/module.rbs +421 -45
  43. data/core/nil_class.rbs +64 -0
  44. data/core/numeric.rbs +620 -142
  45. data/core/object.rbs +453 -81
  46. data/core/object_space.rbs +92 -2
  47. data/core/proc.rbs +482 -285
  48. data/core/process.rbs +443 -34
  49. data/core/ractor.rbs +232 -9
  50. data/core/random.rbs +151 -52
  51. data/core/range.rbs +885 -160
  52. data/core/rational.rbs +122 -6
  53. data/core/rb_config.rbs +14 -4
  54. data/core/refinement.rbs +44 -0
  55. data/core/regexp.rbs +156 -14
  56. data/core/ruby_vm.rbs +42 -3
  57. data/core/signal.rbs +78 -39
  58. data/core/string.rbs +2123 -567
  59. data/core/string_io.rbs +204 -0
  60. data/core/struct.rbs +283 -28
  61. data/core/symbol.rbs +304 -30
  62. data/core/thread.rbs +1288 -688
  63. data/core/thread_group.rbs +66 -10
  64. data/core/time.rbs +643 -217
  65. data/core/trace_point.rbs +100 -12
  66. data/core/true_class.rbs +24 -0
  67. data/core/unbound_method.rbs +73 -7
  68. data/core/warning.rbs +37 -12
  69. data/docs/CONTRIBUTING.md +40 -34
  70. data/docs/stdlib.md +3 -102
  71. data/docs/syntax.md +54 -11
  72. data/ext/rbs_extension/extconf.rb +1 -0
  73. data/ext/rbs_extension/lexer.h +5 -0
  74. data/ext/rbs_extension/lexstate.c +6 -0
  75. data/ext/rbs_extension/parser.c +85 -10
  76. data/ext/rbs_extension/ruby_objs.c +4 -2
  77. data/ext/rbs_extension/ruby_objs.h +2 -2
  78. data/goodcheck.yml +0 -11
  79. data/lib/rbs/annotate/annotations.rb +197 -0
  80. data/lib/rbs/annotate/formatter.rb +80 -0
  81. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  82. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  83. data/lib/rbs/annotate.rb +6 -0
  84. data/lib/rbs/ast/members.rb +21 -13
  85. data/lib/rbs/buffer.rb +17 -11
  86. data/lib/rbs/cli.rb +48 -1
  87. data/lib/rbs/definition_builder/method_builder.rb +28 -16
  88. data/lib/rbs/definition_builder.rb +6 -2
  89. data/lib/rbs/environment.rb +8 -4
  90. data/lib/rbs/location_aux.rb +12 -0
  91. data/lib/rbs/namespace.rb +1 -1
  92. data/lib/rbs/prototype/rb.rb +12 -0
  93. data/lib/rbs/type_alias_regularity.rb +6 -4
  94. data/lib/rbs/type_name.rb +1 -1
  95. data/lib/rbs/types.rb +1 -1
  96. data/lib/rbs/validator.rb +6 -0
  97. data/lib/rbs/version.rb +1 -1
  98. data/lib/rbs/writer.rb +54 -4
  99. data/lib/rbs.rb +0 -2
  100. data/schema/typeParam.json +3 -3
  101. data/sig/annotate/annotations.rbs +102 -0
  102. data/sig/annotate/formatter.rbs +24 -0
  103. data/sig/annotate/rdoc_annotater.rbs +82 -0
  104. data/sig/annotate/rdoc_source.rbs +30 -0
  105. data/sig/buffer.rbs +6 -2
  106. data/sig/cli.rbs +2 -0
  107. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  108. data/sig/location.rbs +6 -0
  109. data/sig/members.rbs +24 -18
  110. data/sig/method_builder.rbs +5 -4
  111. data/sig/method_types.rbs +5 -1
  112. data/sig/polyfill.rbs +78 -0
  113. data/sig/validator.rbs +3 -1
  114. data/sig/writer.rbs +79 -2
  115. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  116. data/stdlib/abbrev/0/array.rbs +26 -0
  117. data/stdlib/base64/0/base64.rbs +31 -0
  118. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  119. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  120. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  121. data/stdlib/cgi/0/core.rbs +649 -21
  122. data/stdlib/coverage/0/coverage.rbs +164 -2
  123. data/stdlib/csv/0/csv.rbs +2862 -398
  124. data/stdlib/date/0/date.rbs +483 -25
  125. data/stdlib/date/0/date_time.rbs +187 -12
  126. data/stdlib/dbm/0/dbm.rbs +152 -17
  127. data/stdlib/digest/0/digest.rbs +146 -0
  128. data/stdlib/erb/0/erb.rbs +65 -245
  129. data/stdlib/fiber/0/fiber.rbs +73 -91
  130. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  131. data/stdlib/find/0/find.rbs +9 -0
  132. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  133. data/stdlib/io-console/0/io-console.rbs +227 -15
  134. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  135. data/stdlib/json/0/json.rbs +1147 -145
  136. data/stdlib/logger/0/formatter.rbs +24 -0
  137. data/stdlib/logger/0/log_device.rbs +64 -0
  138. data/stdlib/logger/0/logger.rbs +165 -13
  139. data/stdlib/logger/0/period.rbs +10 -0
  140. data/stdlib/logger/0/severity.rbs +26 -0
  141. data/stdlib/monitor/0/monitor.rbs +163 -0
  142. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  143. data/stdlib/net-http/0/manifest.yaml +1 -0
  144. data/stdlib/net-http/0/net-http.rbs +1513 -683
  145. data/stdlib/nkf/0/nkf.rbs +372 -0
  146. data/stdlib/objspace/0/objspace.rbs +149 -90
  147. data/stdlib/openssl/0/openssl.rbs +8108 -71
  148. data/stdlib/optparse/0/optparse.rbs +487 -19
  149. data/stdlib/pathname/0/pathname.rbs +425 -124
  150. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  151. data/stdlib/prime/0/integer-extension.rbs +20 -2
  152. data/stdlib/prime/0/prime.rbs +88 -21
  153. data/stdlib/pstore/0/pstore.rbs +102 -0
  154. data/stdlib/pty/0/pty.rbs +64 -14
  155. data/stdlib/resolv/0/resolv.rbs +420 -31
  156. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  157. data/stdlib/rubygems/0/config_file.rbs +33 -1
  158. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  159. data/stdlib/rubygems/0/installer.rbs +13 -1
  160. data/stdlib/rubygems/0/path_support.rbs +4 -1
  161. data/stdlib/rubygems/0/platform.rbs +5 -1
  162. data/stdlib/rubygems/0/request_set.rbs +44 -2
  163. data/stdlib/rubygems/0/requirement.rbs +65 -2
  164. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  165. data/stdlib/rubygems/0/source_list.rbs +13 -0
  166. data/stdlib/rubygems/0/specification.rbs +21 -1
  167. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  168. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  169. data/stdlib/rubygems/0/version.rbs +60 -157
  170. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  171. data/stdlib/set/0/set.rbs +423 -109
  172. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  173. data/stdlib/singleton/0/singleton.rbs +20 -0
  174. data/stdlib/socket/0/addrinfo.rbs +210 -9
  175. data/stdlib/socket/0/basic_socket.rbs +103 -11
  176. data/stdlib/socket/0/ip_socket.rbs +31 -9
  177. data/stdlib/socket/0/socket.rbs +586 -38
  178. data/stdlib/socket/0/tcp_server.rbs +22 -2
  179. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  180. data/stdlib/socket/0/udp_socket.rbs +25 -2
  181. data/stdlib/socket/0/unix_server.rbs +22 -2
  182. data/stdlib/socket/0/unix_socket.rbs +45 -5
  183. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  184. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  185. data/stdlib/time/0/time.rbs +208 -116
  186. data/stdlib/timeout/0/timeout.rbs +10 -0
  187. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  188. data/stdlib/tsort/0/cyclic.rbs +1 -0
  189. data/stdlib/tsort/0/interfaces.rbs +1 -0
  190. data/stdlib/tsort/0/tsort.rbs +42 -0
  191. data/stdlib/uri/0/common.rbs +57 -8
  192. data/stdlib/uri/0/file.rbs +55 -109
  193. data/stdlib/uri/0/ftp.rbs +6 -3
  194. data/stdlib/uri/0/generic.rbs +558 -329
  195. data/stdlib/uri/0/http.rbs +60 -114
  196. data/stdlib/uri/0/https.rbs +8 -102
  197. data/stdlib/uri/0/ldap.rbs +143 -137
  198. data/stdlib/uri/0/ldaps.rbs +8 -102
  199. data/stdlib/uri/0/mailto.rbs +3 -0
  200. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  201. data/stdlib/uri/0/ws.rbs +6 -3
  202. data/stdlib/uri/0/wss.rbs +5 -3
  203. data/stdlib/yaml/0/dbm.rbs +151 -87
  204. data/stdlib/yaml/0/store.rbs +6 -0
  205. data/stdlib/zlib/0/zlib.rbs +90 -31
  206. metadata +18 -6
  207. data/lib/rbs/location.rb +0 -221
  208. data/sig/char_scanner.rbs +0 -9
@@ -0,0 +1,120 @@
1
+ module RBS
2
+ module Annotate
3
+ class RDocSource
4
+ attr_accessor :with_system_dir, :with_gems_dir, :with_site_dir, :with_home_dir
5
+
6
+ attr_reader :extra_dirs
7
+
8
+ attr_reader :stores
9
+
10
+ def initialize
11
+ self.with_system_dir = true
12
+ self.with_gems_dir = false
13
+ self.with_site_dir = false
14
+ self.with_home_dir = false
15
+
16
+ @extra_dirs = []
17
+ @stores = []
18
+ end
19
+
20
+ def load
21
+ @stores.clear()
22
+
23
+ RDoc::RI::Paths.each(with_system_dir, with_site_dir, with_home_dir, with_gems_dir ? :latest : false, *extra_dirs.map(&:to_s)) do |path, type|
24
+ store = RDoc::Store.new(path, type)
25
+ store.load_all
26
+
27
+ @stores << store
28
+ end
29
+ end
30
+
31
+ def find_class(typename)
32
+ classes = []
33
+
34
+ @stores.each do |store|
35
+ if klass = store.find_class_or_module(typename.relative!.to_s)
36
+ classes << klass
37
+ end
38
+ end
39
+
40
+ unless classes.empty?
41
+ classes
42
+ end
43
+ end
44
+
45
+ def docs
46
+ if ds = yield
47
+ unless ds.empty?
48
+ ds.map(&:comment)
49
+ end
50
+ end
51
+ end
52
+
53
+ def class_docs(typename)
54
+ if classes = find_class(typename)
55
+ classes.map {|klass| klass.comment }
56
+ end
57
+ end
58
+
59
+ def find_const(const_name)
60
+ namespace =
61
+ if const_name.namespace.empty?
62
+ TypeName("::Object")
63
+ else
64
+ const_name.namespace.to_type_name
65
+ end
66
+
67
+ if classes = find_class(namespace)
68
+ # @type var consts: Array[RDoc::Constant]
69
+ consts = []
70
+
71
+ classes.each do |klass|
72
+ if const = klass.constants.find {|c| c.name == const_name.name.to_s }
73
+ consts << const
74
+ end
75
+ end
76
+
77
+ unless consts.empty?
78
+ consts
79
+ end
80
+ end
81
+ end
82
+
83
+ def find_method(typename, instance_method: nil, singleton_method: nil)
84
+ if classes = find_class(typename)
85
+ # @type var methods: Array[RDoc::AnyMethod]
86
+ methods = []
87
+
88
+ classes.each do |klass|
89
+ klass.method_list.each do |method|
90
+ if instance_method && !method.singleton && method.name == instance_method.to_s
91
+ methods << method
92
+ end
93
+
94
+ if singleton_method && method.singleton && method.name == singleton_method.to_s
95
+ methods << method
96
+ end
97
+ end
98
+ end
99
+
100
+ unless methods.empty?
101
+ methods
102
+ end
103
+ end
104
+ end
105
+
106
+ def find_attribute(typename, name, singleton:)
107
+ if klasss = find_class(typename)
108
+ # @type var attrs: Array[RDoc::Attr]
109
+ attrs = []
110
+
111
+ klasss.each do |kls|
112
+ attrs.concat(kls.attributes.select {|attr| attr.singleton == singleton && attr.name == name.to_s })
113
+ end
114
+
115
+ attrs unless attrs.empty?
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,6 @@
1
+ require "rdoc"
2
+
3
+ require "rbs/annotate/rdoc_annotator"
4
+ require "rbs/annotate/rdoc_source"
5
+ require "rbs/annotate/annotations"
6
+ require "rbs/annotate/formatter"
@@ -12,8 +12,9 @@ module RBS
12
12
  attr_reader :location
13
13
  attr_reader :comment
14
14
  attr_reader :overload
15
+ attr_reader :visibility
15
16
 
16
- def initialize(name:, kind:, types:, annotations:, location:, comment:, overload:)
17
+ def initialize(name:, kind:, types:, annotations:, location:, comment:, overload:, visibility: nil)
17
18
  @name = name
18
19
  @kind = kind
19
20
  @types = types
@@ -21,6 +22,7 @@ module RBS
21
22
  @location = location
22
23
  @comment = comment
23
24
  @overload = overload ? true : false
25
+ @visibility = visibility
24
26
  end
25
27
 
26
28
  def ==(other)
@@ -28,13 +30,14 @@ module RBS
28
30
  other.name == name &&
29
31
  other.kind == kind &&
30
32
  other.types == types &&
31
- other.overload == overload
33
+ other.overload == overload &&
34
+ other.visibility == visibility
32
35
  end
33
36
 
34
37
  alias eql? ==
35
38
 
36
39
  def hash
37
- self.class.hash ^ name.hash ^ kind.hash ^ types.hash ^ overload.hash
40
+ name.hash ^ kind.hash ^ types.hash ^ overload.hash
38
41
  end
39
42
 
40
43
  def instance?
@@ -49,7 +52,7 @@ module RBS
49
52
  overload
50
53
  end
51
54
 
52
- def update(name: self.name, kind: self.kind, types: self.types, annotations: self.annotations, location: self.location, comment: self.comment, overload: self.overload)
55
+ def update(name: self.name, kind: self.kind, types: self.types, annotations: self.annotations, location: self.location, comment: self.comment, overload: self.overload, visibility: self.visibility)
53
56
  self.class.new(
54
57
  name: name,
55
58
  kind: kind,
@@ -57,7 +60,8 @@ module RBS
57
60
  annotations: annotations,
58
61
  location: location,
59
62
  comment: comment,
60
- overload: overload
63
+ overload: overload,
64
+ visibility: visibility
61
65
  )
62
66
  end
63
67
 
@@ -94,7 +98,7 @@ module RBS
94
98
  alias eql? ==
95
99
 
96
100
  def hash
97
- self.class.hash ^ name.hash ^ type.hash
101
+ name.hash ^ type.hash
98
102
  end
99
103
  end
100
104
 
@@ -164,7 +168,7 @@ module RBS
164
168
  end
165
169
 
166
170
  def hash
167
- self.class.hash ^ name.hash ^ args.hash
171
+ name.hash ^ args.hash
168
172
  end
169
173
  end
170
174
 
@@ -221,8 +225,9 @@ module RBS
221
225
  attr_reader :annotations
222
226
  attr_reader :location
223
227
  attr_reader :comment
228
+ attr_reader :visibility
224
229
 
225
- def initialize(name:, type:, ivar_name:, kind:, annotations:, location:, comment:)
230
+ def initialize(name:, type:, ivar_name:, kind:, annotations:, location:, comment:, visibility: nil)
226
231
  @name = name
227
232
  @type = type
228
233
  @ivar_name = ivar_name
@@ -230,6 +235,7 @@ module RBS
230
235
  @location = location
231
236
  @comment = comment
232
237
  @kind = kind
238
+ @visibility = visibility
233
239
  end
234
240
 
235
241
  def ==(other)
@@ -237,16 +243,17 @@ module RBS
237
243
  other.name == name &&
238
244
  other.type == type &&
239
245
  other.ivar_name == ivar_name &&
240
- other.kind == kind
246
+ other.kind == kind &&
247
+ other.visibility == visibility
241
248
  end
242
249
 
243
250
  alias eql? ==
244
251
 
245
252
  def hash
246
- self.class.hash ^ name.hash ^ type.hash ^ ivar_name.hash ^ kind.hash
253
+ name.hash ^ type.hash ^ ivar_name.hash ^ kind.hash ^ visibility.hash
247
254
  end
248
255
 
249
- def update(name: self.name, type: self.type, ivar_name: self.ivar_name, kind: self.kind, annotations: self.annotations, location: self.location, comment: self.comment)
256
+ def update(name: self.name, type: self.type, ivar_name: self.ivar_name, kind: self.kind, annotations: self.annotations, location: self.location, comment: self.comment, visibility: self.visibility)
250
257
  klass = _ = self.class
251
258
  klass.new(
252
259
  name: name,
@@ -255,7 +262,8 @@ module RBS
255
262
  kind: kind,
256
263
  annotations: annotations,
257
264
  location: location,
258
- comment: comment
265
+ comment: comment,
266
+ visibility: visibility
259
267
  )
260
268
  end
261
269
  end
@@ -372,7 +380,7 @@ module RBS
372
380
  alias eql? ==
373
381
 
374
382
  def hash
375
- self.class.hash ^ new_name.hash ^ old_name.hash ^ kind.hash
383
+ new_name.hash ^ old_name.hash ^ kind.hash
376
384
  end
377
385
 
378
386
  def to_json(state = _ = nil)
data/lib/rbs/buffer.rb CHANGED
@@ -2,23 +2,29 @@ module RBS
2
2
  class Buffer
3
3
  attr_reader :name
4
4
  attr_reader :content
5
- attr_reader :lines
6
- attr_reader :ranges
7
5
 
8
6
  def initialize(name:, content:)
9
7
  @name = name
10
8
  @content = content
9
+ end
11
10
 
12
- @lines = content.lines
11
+ def lines
12
+ @lines ||= content.lines
13
+ end
13
14
 
14
- @ranges = []
15
- offset = 0
16
- lines.each do |line|
17
- size = line.size
18
- range = offset...(offset+size)
19
- ranges << range
20
- offset += size
21
- end
15
+ def ranges
16
+ @ranges ||=
17
+ begin
18
+ @ranges = []
19
+ offset = 0
20
+ lines.each do |line|
21
+ size = line.size
22
+ range = offset...(offset+size)
23
+ @ranges << range
24
+ offset += size
25
+ end
26
+ @ranges
27
+ end
22
28
  end
23
29
 
24
30
  def pos_to_loc(pos)
data/lib/rbs/cli.rb CHANGED
@@ -80,7 +80,7 @@ module RBS
80
80
  @stderr = stderr
81
81
  end
82
82
 
83
- COMMANDS = [:ast, :list, :ancestors, :methods, :method, :validate, :constant, :paths, :prototype, :vendor, :parse, :test, :collection]
83
+ COMMANDS = [:ast, :annotate, :list, :ancestors, :methods, :method, :validate, :constant, :paths, :prototype, :vendor, :parse, :test, :collection]
84
84
 
85
85
  def parse_logging_options(opts)
86
86
  opts.on("--log-level LEVEL", "Specify log level (defaults to `warn`)") do |level|
@@ -791,6 +791,53 @@ Examples:
791
791
  exit 1 if syntax_error
792
792
  end
793
793
 
794
+ def run_annotate(args, options)
795
+ require "rbs/annotate"
796
+
797
+ source = RBS::Annotate::RDocSource.new()
798
+ annotator = RBS::Annotate::RDocAnnotator.new(source: source)
799
+
800
+ preserve = true
801
+
802
+ OptionParser.new do |opts|
803
+ opts.banner = <<-EOB
804
+ Usage: rbs annotate [options...] [files...]
805
+
806
+ Import documents from RDoc and update RBS files.
807
+
808
+ Examples:
809
+
810
+ $ rbs annotate stdlib/pathname/**/*.rbs
811
+
812
+ Options:
813
+ EOB
814
+
815
+ opts.on("--[no-]system", "Load RDoc from system (defaults to true)") {|b| source.with_system_dir = b }
816
+ opts.on("--[no-]gems", "Load RDoc from gems (defaults to false)") {|b| source.with_gems_dir = b }
817
+ opts.on("--[no-]site", "Load RDoc from site directory (defaults to false)") {|b| source.with_site_dir = b }
818
+ opts.on("--[no-]home", "Load RDoc from home directory (defaults to false)") {|b| source.with_home_dir = b }
819
+ opts.on("-d", "--dir DIRNAME", "Load RDoc from DIRNAME") {|d| source.extra_dirs << Pathname(d) }
820
+ opts.on("--[no-]arglists", "Generate arglists section (defaults to true)") {|b| annotator.include_arg_lists = b }
821
+ opts.on("--[no-]filename", "Include source file name in the documentation (defaults to true)") {|b| annotator.include_filename = b }
822
+ opts.on("--[no-]preserve", "Try preserve the format of the original file (defaults to true)") {|b| preserve = b }
823
+ end.parse!(args)
824
+
825
+ source.load()
826
+
827
+ args.each do |file|
828
+ path = Pathname(file)
829
+ if path.directory?
830
+ Pathname.glob((path + "**/*.rbs").to_s).each do |path|
831
+ stdout.puts "Processing #{path}..."
832
+ annotator.annotate_file(path, preserve: preserve)
833
+ end
834
+ else
835
+ stdout.puts "Processing #{path}..."
836
+ annotator.annotate_file(path, preserve: preserve)
837
+ end
838
+ end
839
+ end
840
+
794
841
  def test_opt options
795
842
  opts = []
796
843
 
@@ -10,7 +10,11 @@ module RBS
10
10
  end
11
11
 
12
12
  def accessibility
13
- accessibilities[0]
13
+ if original.is_a?(AST::Members::Alias)
14
+ raise "alias member doesn't have accessibility"
15
+ else
16
+ accessibilities[0] or raise
17
+ end
14
18
  end
15
19
 
16
20
  def self.empty(name:, type:)
@@ -102,22 +106,32 @@ module RBS
102
106
  each_member_with_accessibility(d.decl.members) do |member, accessibility|
103
107
  case member
104
108
  when AST::Members::MethodDefinition
105
- if member.instance?
106
- build_method(methods,
107
- type,
108
- member: member.update(types: member.types.map {|type| type.sub(subst) }),
109
- accessibility: accessibility)
109
+ case member.kind
110
+ when :instance
111
+ build_method(
112
+ methods,
113
+ type,
114
+ member: member.update(types: member.types.map {|type| type.sub(subst) }),
115
+ accessibility: member.visibility || accessibility
116
+ )
117
+ when :singleton_instance
118
+ build_method(
119
+ methods,
120
+ type,
121
+ member: member.update(types: member.types.map {|type| type.sub(subst) }),
122
+ accessibility: :private
123
+ )
110
124
  end
111
125
  when AST::Members::AttrReader, AST::Members::AttrWriter, AST::Members::AttrAccessor
112
126
  if member.kind == :instance
113
127
  build_attribute(methods,
114
128
  type,
115
129
  member: member.update(type: member.type.sub(subst)),
116
- accessibility: accessibility)
130
+ accessibility: member.visibility || accessibility)
117
131
  end
118
132
  when AST::Members::Alias
119
133
  if member.kind == :instance
120
- build_alias(methods, type, member: member, accessibility: accessibility)
134
+ build_alias(methods, type, member: member)
121
135
  end
122
136
  end
123
137
  end
@@ -134,19 +148,19 @@ module RBS
134
148
 
135
149
  Methods.new(type: type).tap do |methods|
136
150
  entry.decls.each do |d|
137
- each_member_with_accessibility(d.decl.members) do |member, accessibility|
151
+ d.decl.members.each do |member|
138
152
  case member
139
153
  when AST::Members::MethodDefinition
140
154
  if member.singleton?
141
- build_method(methods, type, member: member, accessibility: accessibility)
155
+ build_method(methods, type, member: member, accessibility: member.visibility || :public)
142
156
  end
143
157
  when AST::Members::AttrReader, AST::Members::AttrWriter, AST::Members::AttrAccessor
144
158
  if member.kind == :singleton
145
- build_attribute(methods, type, member: member, accessibility: accessibility)
159
+ build_attribute(methods, type, member: member, accessibility: member.visibility || :public)
146
160
  end
147
161
  when AST::Members::Alias
148
162
  if member.kind == :singleton
149
- build_alias(methods, type, member: member, accessibility: accessibility)
163
+ build_alias(methods, type, member: member)
150
164
  end
151
165
  end
152
166
  end
@@ -168,18 +182,16 @@ module RBS
168
182
  when AST::Members::MethodDefinition
169
183
  build_method(methods, type, member: member, accessibility: :public)
170
184
  when AST::Members::Alias
171
- build_alias(methods, type, member: member, accessibility: :public)
185
+ build_alias(methods, type, member: member)
172
186
  end
173
187
  end
174
188
  end.validate!
175
189
  end
176
190
  end
177
191
 
178
- def build_alias(methods, type, member:, accessibility:)
192
+ def build_alias(methods, type, member:)
179
193
  defn = methods.methods[member.new_name] ||= Methods::Definition.empty(type: type, name: member.new_name)
180
-
181
194
  defn.originals << member
182
- defn.accessibilities << accessibility
183
195
  end
184
196
 
185
197
  def build_attribute(methods, type, member:, accessibility:)
@@ -539,8 +539,12 @@ module RBS
539
539
 
540
540
  if method_types
541
541
  method_types.each do |method_type|
542
+ merged_params = type_params
543
+ .reject {|param| method_type.type_param_names.include?(param.name) }
544
+ .concat(method_type.type_params)
545
+
542
546
  result = calculator.in_method_type(method_type: method_type, variables: param_names)
543
- validate_params_with(type_params, result: result) do |param|
547
+ validate_params_with(merged_params, result: result) do |param|
544
548
  raise InvalidVarianceAnnotationError.new(
545
549
  type_name: definition.type_name,
546
550
  param: param,
@@ -583,7 +587,7 @@ module RBS
583
587
  defs: original_method.defs.map do |defn|
584
588
  defn.update(defined_in: definition.type_name, implemented_in: definition.type_name)
585
589
  end,
586
- accessibility: method_def.accessibility,
590
+ accessibility: original_method.accessibility,
587
591
  alias_of: original_method
588
592
  )
589
593
  else
@@ -357,7 +357,8 @@ module RBS
357
357
  comment: member.comment,
358
358
  overload: member.overload?,
359
359
  annotations: member.annotations,
360
- location: member.location
360
+ location: member.location,
361
+ visibility: member.visibility
361
362
  )
362
363
  when AST::Members::AttrAccessor
363
364
  AST::Members::AttrAccessor.new(
@@ -367,7 +368,8 @@ module RBS
367
368
  annotations: member.annotations,
368
369
  comment: member.comment,
369
370
  location: member.location,
370
- ivar_name: member.ivar_name
371
+ ivar_name: member.ivar_name,
372
+ visibility: member.visibility
371
373
  )
372
374
  when AST::Members::AttrReader
373
375
  AST::Members::AttrReader.new(
@@ -377,7 +379,8 @@ module RBS
377
379
  annotations: member.annotations,
378
380
  comment: member.comment,
379
381
  location: member.location,
380
- ivar_name: member.ivar_name
382
+ ivar_name: member.ivar_name,
383
+ visibility: member.visibility
381
384
  )
382
385
  when AST::Members::AttrWriter
383
386
  AST::Members::AttrWriter.new(
@@ -387,7 +390,8 @@ module RBS
387
390
  annotations: member.annotations,
388
391
  comment: member.comment,
389
392
  location: member.location,
390
- ivar_name: member.ivar_name
393
+ ivar_name: member.ivar_name,
394
+ visibility: member.visibility
391
395
  )
392
396
  when AST::Members::InstanceVariable
393
397
  AST::Members::InstanceVariable.new(
@@ -119,5 +119,17 @@ module RBS
119
119
  enum_for(:each_required_key)
120
120
  end
121
121
  end
122
+
123
+ def key?(name)
124
+ optional_key?(name) || required_key?(name)
125
+ end
126
+
127
+ def optional_key?(name)
128
+ _optional_keys.include?(name)
129
+ end
130
+
131
+ def required_key?(name)
132
+ _required_keys.include?(name)
133
+ end
122
134
  end
123
135
  end
data/lib/rbs/namespace.rb CHANGED
@@ -59,7 +59,7 @@ module RBS
59
59
  alias eql? ==
60
60
 
61
61
  def hash
62
- self.class.hash ^ path.hash ^ absolute?.hash
62
+ path.hash ^ absolute?.hash
63
63
  end
64
64
 
65
65
  def split
@@ -197,6 +197,18 @@ module RBS
197
197
  )
198
198
  end
199
199
  end
200
+ when :prepend
201
+ args.each do |arg|
202
+ if (name = const_to_name(arg))
203
+ decls << AST::Members::Prepend.new(
204
+ name: name,
205
+ args: [],
206
+ annotations: [],
207
+ location: nil,
208
+ comment: comments[node.first_lineno - 1]
209
+ )
210
+ end
211
+ end
200
212
  when :extend
201
213
  args.each do |arg|
202
214
  if (name = const_to_name(arg, context: context))
@@ -55,7 +55,7 @@ module RBS
55
55
  end
56
56
 
57
57
  def build_alias_type(name)
58
- entry = env.alias_decls[name] or raise "Unknown alias name: #{name}"
58
+ entry = env.alias_decls[name] or return
59
59
  unless entry.decl.type_params.empty?
60
60
  as = entry.decl.type_params.each.map {|param| Types::Variable.new(name: param.name, location: nil) }
61
61
  Types::Alias.new(name: name, args: as, location: nil)
@@ -85,9 +85,11 @@ module RBS
85
85
  end
86
86
  # @type var each_child: TSort::_EachChild[TypeName]
87
87
  each_child = __skip__ = -> (name, &block) do
88
- type = builder.expand_alias1(name)
89
- each_alias_type(type) do |ty|
90
- block[ty.name]
88
+ if env.alias_decls.key?(name)
89
+ type = builder.expand_alias1(name)
90
+ each_alias_type(type) do |ty|
91
+ block[ty.name]
92
+ end
91
93
  end
92
94
  end
93
95
 
data/lib/rbs/type_name.rb CHANGED
@@ -27,7 +27,7 @@ module RBS
27
27
  alias eql? ==
28
28
 
29
29
  def hash
30
- self.class.hash ^ namespace.hash ^ name.hash
30
+ namespace.hash ^ name.hash
31
31
  end
32
32
 
33
33
  def to_s
data/lib/rbs/types.rb CHANGED
@@ -213,7 +213,7 @@ module RBS
213
213
  alias eql? ==
214
214
 
215
215
  def hash
216
- self.class.hash ^ name.hash ^ args.hash
216
+ name.hash ^ args.hash
217
217
  end
218
218
 
219
219
  def free_variables(set = Set.new)
data/lib/rbs/validator.rb CHANGED
@@ -73,6 +73,8 @@ module RBS
73
73
  if set = result.incompatible?(entry.decl.type_params)
74
74
  set.each do |param_name|
75
75
  param = entry.decl.type_params.find {|param| param.name == param_name } or raise
76
+ next if param.unchecked?
77
+
76
78
  raise InvalidVarianceAnnotationError.new(
77
79
  type_name: type_name,
78
80
  param: param,
@@ -87,6 +89,10 @@ module RBS
87
89
  location: entry.decl.location&.aref(:type_params)
88
90
  )
89
91
  end
92
+
93
+ if block_given?
94
+ yield entry.decl.type
95
+ end
90
96
  end
91
97
 
92
98
  def validate_method_definition(method_def, type_name:)
data/lib/rbs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RBS
2
- VERSION = "2.0.0"
2
+ VERSION = "2.2.2"
3
3
  end