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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +11 -8
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/dependabot.yml +1 -1
  7. data/.github/workflows/ruby.yml +17 -34
  8. data/.github/workflows/typecheck.yml +2 -2
  9. data/.github/workflows/valgrind.yml +42 -0
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/README.md +1 -1
  13. data/Rakefile +32 -5
  14. data/config.yml +46 -0
  15. data/core/array.rbs +96 -46
  16. data/core/binding.rbs +0 -2
  17. data/core/builtin.rbs +2 -2
  18. data/core/comparable.rbs +13 -6
  19. data/core/complex.rbs +55 -41
  20. data/core/dir.rbs +4 -4
  21. data/core/encoding.rbs +7 -10
  22. data/core/enumerable.rbs +90 -3
  23. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  24. data/core/enumerator.rbs +63 -1
  25. data/core/errno.rbs +8 -0
  26. data/core/errors.rbs +28 -1
  27. data/core/exception.rbs +2 -2
  28. data/core/fiber.rbs +40 -20
  29. data/core/file.rbs +108 -78
  30. data/core/file_test.rbs +1 -1
  31. data/core/float.rbs +225 -69
  32. data/core/gc.rbs +417 -281
  33. data/core/hash.rbs +1023 -727
  34. data/core/integer.rbs +104 -110
  35. data/core/io/buffer.rbs +21 -10
  36. data/core/io/wait.rbs +11 -33
  37. data/core/io.rbs +82 -19
  38. data/core/kernel.rbs +70 -59
  39. data/core/marshal.rbs +1 -1
  40. data/core/match_data.rbs +1 -1
  41. data/core/math.rbs +42 -3
  42. data/core/method.rbs +63 -27
  43. data/core/module.rbs +103 -26
  44. data/core/nil_class.rbs +3 -3
  45. data/core/numeric.rbs +43 -35
  46. data/core/object.rbs +3 -3
  47. data/core/object_space.rbs +21 -15
  48. data/core/pathname.rbs +1272 -0
  49. data/core/proc.rbs +30 -25
  50. data/core/process.rbs +4 -2
  51. data/core/ractor.rbs +361 -509
  52. data/core/random.rbs +17 -0
  53. data/core/range.rbs +113 -16
  54. data/core/rational.rbs +56 -85
  55. data/core/rbs/unnamed/argf.rbs +2 -2
  56. data/core/rbs/unnamed/env_class.rbs +1 -1
  57. data/core/rbs/unnamed/random.rbs +4 -113
  58. data/core/regexp.rbs +25 -20
  59. data/core/ruby.rbs +53 -0
  60. data/core/ruby_vm.rbs +6 -4
  61. data/core/rubygems/errors.rbs +3 -70
  62. data/core/rubygems/rubygems.rbs +11 -79
  63. data/core/rubygems/version.rbs +2 -3
  64. data/core/set.rbs +488 -359
  65. data/core/signal.rbs +24 -14
  66. data/core/string.rbs +3171 -1241
  67. data/core/struct.rbs +1 -1
  68. data/core/symbol.rbs +17 -11
  69. data/core/thread.rbs +95 -33
  70. data/core/time.rbs +35 -9
  71. data/core/trace_point.rbs +7 -4
  72. data/core/unbound_method.rbs +14 -6
  73. data/docs/aliases.md +79 -0
  74. data/docs/collection.md +2 -2
  75. data/docs/encoding.md +56 -0
  76. data/docs/gem.md +0 -1
  77. data/docs/inline.md +470 -0
  78. data/docs/sigs.md +3 -3
  79. data/docs/syntax.md +33 -4
  80. data/docs/type_fingerprint.md +21 -0
  81. data/exe/rbs +1 -1
  82. data/ext/rbs_extension/ast_translation.c +77 -3
  83. data/ext/rbs_extension/ast_translation.h +3 -0
  84. data/ext/rbs_extension/class_constants.c +8 -2
  85. data/ext/rbs_extension/class_constants.h +4 -0
  86. data/ext/rbs_extension/extconf.rb +5 -1
  87. data/ext/rbs_extension/legacy_location.c +5 -5
  88. data/ext/rbs_extension/main.c +37 -20
  89. data/include/rbs/ast.h +85 -38
  90. data/include/rbs/defines.h +27 -0
  91. data/include/rbs/lexer.h +30 -11
  92. data/include/rbs/parser.h +6 -6
  93. data/include/rbs/string.h +0 -2
  94. data/include/rbs/util/rbs_allocator.h +34 -13
  95. data/include/rbs/util/rbs_assert.h +12 -1
  96. data/include/rbs/util/rbs_encoding.h +2 -0
  97. data/include/rbs/util/rbs_unescape.h +2 -1
  98. data/lib/rbs/ast/annotation.rb +1 -1
  99. data/lib/rbs/ast/comment.rb +1 -1
  100. data/lib/rbs/ast/declarations.rb +10 -10
  101. data/lib/rbs/ast/members.rb +14 -14
  102. data/lib/rbs/ast/ruby/annotations.rb +137 -0
  103. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  104. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  105. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  106. data/lib/rbs/ast/ruby/members.rb +159 -1
  107. data/lib/rbs/ast/type_param.rb +24 -4
  108. data/lib/rbs/buffer.rb +20 -15
  109. data/lib/rbs/cli/diff.rb +16 -15
  110. data/lib/rbs/cli/validate.rb +38 -51
  111. data/lib/rbs/cli.rb +52 -19
  112. data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
  113. data/lib/rbs/collection/sources/git.rb +1 -0
  114. data/lib/rbs/definition.rb +1 -1
  115. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  116. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  117. data/lib/rbs/definition_builder.rb +91 -2
  118. data/lib/rbs/diff.rb +7 -1
  119. data/lib/rbs/environment.rb +227 -74
  120. data/lib/rbs/environment_loader.rb +0 -6
  121. data/lib/rbs/errors.rb +27 -7
  122. data/lib/rbs/inline_parser.rb +341 -5
  123. data/lib/rbs/location_aux.rb +1 -1
  124. data/lib/rbs/locator.rb +5 -1
  125. data/lib/rbs/method_type.rb +5 -3
  126. data/lib/rbs/parser_aux.rb +2 -2
  127. data/lib/rbs/prototype/rb.rb +2 -2
  128. data/lib/rbs/prototype/rbi.rb +2 -0
  129. data/lib/rbs/prototype/runtime.rb +8 -0
  130. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  131. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  132. data/lib/rbs/subtractor.rb +3 -1
  133. data/lib/rbs/test/type_check.rb +16 -2
  134. data/lib/rbs/type_name.rb +1 -1
  135. data/lib/rbs/types.rb +27 -27
  136. data/lib/rbs/validator.rb +2 -2
  137. data/lib/rbs/version.rb +1 -1
  138. data/lib/rbs.rb +1 -1
  139. data/lib/rdoc/discover.rb +1 -1
  140. data/lib/rdoc_plugin/parser.rb +1 -1
  141. data/rbs.gemspec +3 -2
  142. data/schema/typeParam.json +17 -1
  143. data/sig/ast/ruby/annotations.rbs +124 -0
  144. data/sig/ast/ruby/comment_block.rbs +8 -0
  145. data/sig/ast/ruby/declarations.rbs +102 -4
  146. data/sig/ast/ruby/members.rbs +87 -1
  147. data/sig/cli/diff.rbs +5 -11
  148. data/sig/cli/validate.rbs +13 -4
  149. data/sig/cli.rbs +18 -18
  150. data/sig/definition.rbs +6 -1
  151. data/sig/environment.rbs +70 -12
  152. data/sig/errors.rbs +13 -6
  153. data/sig/inline_parser.rbs +39 -2
  154. data/sig/locator.rbs +0 -2
  155. data/sig/manifest.yaml +0 -1
  156. data/sig/method_builder.rbs +3 -1
  157. data/sig/method_types.rbs +1 -1
  158. data/sig/parser.rbs +16 -2
  159. data/sig/resolver/type_name_resolver.rbs +35 -7
  160. data/sig/source.rbs +3 -3
  161. data/sig/type_param.rbs +13 -8
  162. data/sig/types.rbs +4 -4
  163. data/src/ast.c +80 -1
  164. data/src/lexer.c +1392 -1313
  165. data/src/lexer.re +3 -0
  166. data/src/lexstate.c +58 -37
  167. data/src/location.c +4 -4
  168. data/src/parser.c +412 -145
  169. data/src/string.c +0 -48
  170. data/src/util/rbs_allocator.c +89 -71
  171. data/src/util/rbs_assert.c +1 -1
  172. data/src/util/rbs_buffer.c +2 -2
  173. data/src/util/rbs_constant_pool.c +10 -10
  174. data/src/util/rbs_encoding.c +4 -8
  175. data/src/util/rbs_unescape.c +56 -20
  176. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  177. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  178. data/stdlib/cgi/0/core.rbs +9 -393
  179. data/stdlib/cgi/0/manifest.yaml +1 -0
  180. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  181. data/stdlib/coverage/0/coverage.rbs +3 -1
  182. data/stdlib/date/0/date.rbs +67 -59
  183. data/stdlib/date/0/date_time.rbs +1 -1
  184. data/stdlib/delegate/0/delegator.rbs +10 -7
  185. data/stdlib/digest/0/digest.rbs +110 -0
  186. data/stdlib/erb/0/erb.rbs +737 -347
  187. data/stdlib/fileutils/0/fileutils.rbs +20 -14
  188. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  189. data/stdlib/json/0/json.rbs +82 -28
  190. data/stdlib/net-http/0/net-http.rbs +3 -0
  191. data/stdlib/objspace/0/objspace.rbs +9 -27
  192. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  193. data/stdlib/open3/0/open3.rbs +459 -1
  194. data/stdlib/openssl/0/openssl.rbs +331 -228
  195. data/stdlib/optparse/0/optparse.rbs +8 -3
  196. data/stdlib/pathname/0/pathname.rbs +9 -1379
  197. data/stdlib/psych/0/psych.rbs +4 -4
  198. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  199. data/stdlib/rdoc/0/code_object.rbs +2 -1
  200. data/stdlib/rdoc/0/parser.rbs +1 -1
  201. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  202. data/stdlib/rdoc/0/store.rbs +1 -1
  203. data/stdlib/resolv/0/resolv.rbs +25 -68
  204. data/stdlib/ripper/0/ripper.rbs +2 -2
  205. data/stdlib/securerandom/0/manifest.yaml +2 -0
  206. data/stdlib/securerandom/0/securerandom.rbs +6 -19
  207. data/stdlib/singleton/0/singleton.rbs +3 -0
  208. data/stdlib/socket/0/socket.rbs +13 -1
  209. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  210. data/stdlib/stringio/0/stringio.rbs +1176 -85
  211. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  212. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  213. data/stdlib/time/0/time.rbs +1 -1
  214. data/stdlib/timeout/0/timeout.rbs +63 -7
  215. data/stdlib/tsort/0/cyclic.rbs +3 -0
  216. data/stdlib/uri/0/common.rbs +16 -2
  217. data/stdlib/uri/0/file.rbs +1 -1
  218. data/stdlib/uri/0/generic.rbs +24 -16
  219. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  220. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  221. data/stdlib/zlib/0/gzip_writer.rbs +1 -1
  222. data/stdlib/zlib/0/zstream.rbs +1 -0
  223. metadata +30 -4
@@ -16,17 +16,67 @@ module RBS
16
16
  end
17
17
 
18
18
  class ClassDecl < Base
19
+ class SuperClass
20
+ attr_reader :type_name_location
21
+
22
+ attr_reader :operator_location
23
+
24
+ attr_reader :type_name
25
+
26
+ attr_reader :type_annotation
27
+
28
+ def initialize(type_name_location, operator_location, type_name, type_annotation)
29
+ @type_name_location = type_name_location
30
+ @operator_location = operator_location
31
+ @type_name = type_name
32
+ @type_annotation = type_annotation
33
+ end
34
+
35
+ def type_args
36
+ if type_annotation
37
+ type_annotation.type_args
38
+ else
39
+ []
40
+ end
41
+ end
42
+
43
+ def location
44
+ if type_annotation
45
+ Location.new(
46
+ type_name_location.buffer,
47
+ type_name_location.start_pos,
48
+ type_annotation.location.end_pos
49
+ )
50
+ else
51
+ type_name_location
52
+ end
53
+ end
54
+
55
+ alias name type_name
56
+ alias args type_args
57
+
58
+ def type_fingerprint
59
+ [
60
+ type_name.to_s,
61
+ type_annotation&.type_fingerprint
62
+ ]
63
+ end
64
+ end
65
+
19
66
  attr_reader :class_name
20
67
 
21
68
  attr_reader :members
22
69
 
23
70
  attr_reader :node
24
71
 
25
- def initialize(buffer, name, node)
72
+ attr_reader :super_class
73
+
74
+ def initialize(buffer, name, node, super_class)
26
75
  super(buffer)
27
76
  @class_name = name
28
77
  @node = node
29
78
  @members = []
79
+ @super_class = super_class
30
80
  end
31
81
 
32
82
  def each_decl(&block)
@@ -39,13 +89,26 @@ module RBS
39
89
  end
40
90
  end
41
91
 
42
- def super_class = nil
43
-
44
92
  def type_params = []
45
93
 
46
94
  def location
47
95
  rbs_location(node.location)
48
96
  end
97
+
98
+ def name_location
99
+ rbs_location(node.constant_path.location)
100
+ end
101
+
102
+ def type_fingerprint
103
+ result = [] #: Array[untyped]
104
+
105
+ result << "decls/class"
106
+ result << class_name.to_s
107
+ result << super_class&.type_fingerprint
108
+ result << members.map { _1.type_fingerprint }
109
+
110
+ result
111
+ end
49
112
  end
50
113
 
51
114
  class ModuleDecl < Base
@@ -79,6 +142,138 @@ module RBS
79
142
  def location
80
143
  rbs_location(node.location)
81
144
  end
145
+
146
+ def name_location
147
+ rbs_location(node.constant_path.location)
148
+ end
149
+
150
+ def type_fingerprint
151
+ result = [] #: Array[untyped]
152
+
153
+ result << "decls/module"
154
+ result << module_name.to_s
155
+ result << members.map { _1.type_fingerprint}
156
+
157
+ result
158
+ end
159
+ end
160
+
161
+ class ConstantDecl < Base
162
+ attr_reader :leading_comment
163
+ attr_reader :constant_name
164
+ attr_reader :node
165
+ attr_reader :type_annotation
166
+
167
+ def initialize(buffer, constant_name, node, leading_comment, type_annotation)
168
+ super(buffer)
169
+ @constant_name = constant_name
170
+ @node = node
171
+ @leading_comment = leading_comment
172
+ @type_annotation = type_annotation
173
+ end
174
+
175
+ def location
176
+ rbs_location(node.location)
177
+ end
178
+
179
+ def name_location
180
+ case node
181
+ when Prism::ConstantWriteNode
182
+ rbs_location(node.name_loc)
183
+ when Prism::ConstantPathWriteNode
184
+ rbs_location(node.target.location)
185
+ end
186
+ end
187
+
188
+ def type
189
+ return type_annotation.type if type_annotation
190
+
191
+ case node.value
192
+ when Prism::IntegerNode
193
+ BuiltinNames::Integer.instance_type
194
+ when Prism::FloatNode
195
+ BuiltinNames::Float.instance_type
196
+ when Prism::StringNode
197
+ BuiltinNames::String.instance_type
198
+ when Prism::TrueNode, Prism::FalseNode
199
+ Types::Bases::Bool.new(location: nil)
200
+ when Prism::SymbolNode
201
+ BuiltinNames::Symbol.instance_type
202
+ when Prism::NilNode
203
+ Types::Bases::Nil.new(location: nil)
204
+ else
205
+ Types::Bases::Any.new(location: nil)
206
+ end
207
+ end
208
+
209
+ def comment
210
+ leading_comment&.as_comment
211
+ end
212
+
213
+ def type_fingerprint
214
+ [
215
+ "decls/constant",
216
+ constant_name.to_s,
217
+ type.to_s,
218
+ leading_comment&.as_comment&.string
219
+ ]
220
+ end
221
+ end
222
+
223
+ class ClassModuleAliasDecl < Base
224
+ attr_reader :node
225
+ attr_reader :leading_comment
226
+ attr_reader :new_name
227
+ attr_reader :infered_old_name
228
+ attr_reader :annotation
229
+
230
+ def initialize(buffer, node, new_name, infered_old_name, leading_comment, annotation)
231
+ super(buffer)
232
+ @node = node
233
+ @new_name = new_name
234
+ @infered_old_name = infered_old_name
235
+ @leading_comment = leading_comment
236
+ @annotation = annotation
237
+ end
238
+
239
+ def location
240
+ rbs_location(node.location)
241
+ end
242
+
243
+ def name_location
244
+ case node
245
+ when Prism::ConstantWriteNode
246
+ rbs_location(node.name_loc)
247
+ when Prism::ConstantPathWriteNode
248
+ rbs_location(node.target.location)
249
+ end
250
+ end
251
+
252
+ def old_name
253
+ # Return explicit type name from annotation if provided, otherwise use inferred name
254
+ case
255
+ when annotation.type_name
256
+ annotation.type_name
257
+ when infered_old_name
258
+ infered_old_name
259
+ else
260
+ raise "No old name available"
261
+ end
262
+ end
263
+
264
+ def comment
265
+ leading_comment&.as_comment
266
+ end
267
+
268
+ def type_fingerprint
269
+ [
270
+ "decls/class_module_alias",
271
+ annotation.type_fingerprint,
272
+ new_name.to_s,
273
+ old_name.to_s,
274
+ leading_comment&.as_comment&.string
275
+ ]
276
+ end
82
277
  end
83
278
  end
84
279
  end
@@ -15,6 +15,10 @@ module RBS
15
15
  rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
16
16
  nil
17
17
  end
18
+ when Prism::ConstantWriteNode
19
+ TypeName.new(name: node.name, namespace: Namespace.empty)
20
+ when Prism::ConstantPathWriteNode
21
+ constant_as_type_name(node.target)
18
22
  end
19
23
  end
20
24
  end
@@ -28,6 +28,10 @@ module RBS
28
28
  end #: self
29
29
  end
30
30
 
31
+ def type_fingerprint
32
+ return_type_annotation&.type_fingerprint
33
+ end
34
+
31
35
  def method_type
32
36
  return_type =
33
37
  case return_type_annotation
@@ -175,6 +179,17 @@ module RBS
175
179
  ]
176
180
  end
177
181
  end
182
+
183
+ def type_fingerprint
184
+ case type_annotations
185
+ when DocStyle
186
+ type_annotations.type_fingerprint
187
+ when Array
188
+ type_annotations.map(&:type_fingerprint)
189
+ when nil
190
+ nil
191
+ end
192
+ end
178
193
  end
179
194
 
180
195
  class DefMember < Base
@@ -183,12 +198,14 @@ module RBS
183
198
  attr_reader :name
184
199
  attr_reader :node
185
200
  attr_reader :method_type
201
+ attr_reader :leading_comment
186
202
 
187
- def initialize(buffer, name, node, method_type)
203
+ def initialize(buffer, name, node, method_type, leading_comment)
188
204
  super(buffer)
189
205
  @name = name
190
206
  @node = node
191
207
  @method_type = method_type
208
+ @leading_comment = leading_comment
192
209
  end
193
210
 
194
211
  def location
@@ -206,6 +223,147 @@ module RBS
206
223
  def annotations
207
224
  []
208
225
  end
226
+
227
+ def name_location
228
+ rbs_location(node.name_loc)
229
+ end
230
+
231
+ def type_fingerprint
232
+ [
233
+ "members/def",
234
+ name.to_s,
235
+ method_type.type_fingerprint,
236
+ leading_comment&.as_comment&.string
237
+ ]
238
+ end
239
+ end
240
+
241
+ class MixinMember < Base
242
+ attr_reader :node
243
+ attr_reader :module_name
244
+ attr_reader :annotation
245
+
246
+ def initialize(buffer, node, module_name, annotation)
247
+ super(buffer)
248
+ @node = node
249
+ @module_name = module_name
250
+ @annotation = annotation
251
+ end
252
+
253
+ def location
254
+ rbs_location(node.location)
255
+ end
256
+
257
+ def name_location
258
+ args = node.arguments or raise
259
+ first_arg = args.arguments.first or raise
260
+
261
+ rbs_location(first_arg.location)
262
+ end
263
+
264
+ def type_args
265
+ annotation&.type_args || []
266
+ end
267
+
268
+ def type_fingerprint
269
+ [
270
+ "members/mixin",
271
+ self.class.name,
272
+ module_name.to_s,
273
+ annotation&.type_fingerprint
274
+ ]
275
+ end
276
+ end
277
+
278
+ class IncludeMember < MixinMember
279
+ end
280
+
281
+ class ExtendMember < MixinMember
282
+ end
283
+
284
+ class PrependMember < MixinMember
285
+ end
286
+
287
+ class AttributeMember < Base
288
+ attr_reader :node
289
+ attr_reader :name_nodes
290
+ attr_reader :type_annotation
291
+ attr_reader :leading_comment
292
+
293
+ def initialize(buffer, node, name_nodes, leading_comment, type_annotation)
294
+ super(buffer)
295
+ @node = node
296
+ @name_nodes = name_nodes
297
+ @leading_comment = leading_comment
298
+ @type_annotation = type_annotation
299
+ end
300
+
301
+ def names
302
+ name_nodes.map do |node|
303
+ node.unescaped.to_sym
304
+ end
305
+ end
306
+
307
+ def location
308
+ rbs_location(node.location)
309
+ end
310
+
311
+ def name_locations
312
+ name_nodes.map do |name_node|
313
+ rbs_location(name_node.location)
314
+ end
315
+ end
316
+
317
+ def type
318
+ type_annotation&.type
319
+ end
320
+
321
+ def type_fingerprint
322
+ [
323
+ "members/attribute",
324
+ self.class.name,
325
+ names.map(&:to_s),
326
+ type_annotation&.type_fingerprint,
327
+ leading_comment&.as_comment&.string
328
+ ]
329
+ end
330
+ end
331
+
332
+ class AttrReaderMember < AttributeMember
333
+ end
334
+
335
+ class AttrWriterMember < AttributeMember
336
+ end
337
+
338
+ class AttrAccessorMember < AttributeMember
339
+ end
340
+
341
+ class InstanceVariableMember < Base
342
+ attr_reader :annotation
343
+
344
+ def initialize(buffer, annotation)
345
+ super(buffer)
346
+ @annotation = annotation
347
+ end
348
+
349
+ def name
350
+ annotation.ivar_name
351
+ end
352
+
353
+ def type
354
+ annotation.type
355
+ end
356
+
357
+ def location
358
+ annotation.location
359
+ end
360
+
361
+ def type_fingerprint
362
+ [
363
+ "members/instance_variable",
364
+ annotation.type_fingerprint
365
+ ]
366
+ end
209
367
  end
210
368
  end
211
369
  end
@@ -3,12 +3,13 @@
3
3
  module RBS
4
4
  module AST
5
5
  class TypeParam
6
- attr_reader :name, :variance, :location, :upper_bound_type, :default_type
6
+ attr_reader :name, :variance, :location, :upper_bound_type, :lower_bound_type, :default_type
7
7
 
8
- def initialize(name:, variance:, upper_bound:, location:, default_type: nil, unchecked: false)
8
+ def initialize(name:, variance:, upper_bound:, lower_bound:, location:, default_type: nil, unchecked: false)
9
9
  @name = name
10
10
  @variance = variance
11
11
  @upper_bound_type = upper_bound
12
+ @lower_bound_type = lower_bound
12
13
  @location = location
13
14
  @default_type = default_type
14
15
  @unchecked = unchecked
@@ -21,6 +22,13 @@ module RBS
21
22
  end
22
23
  end
23
24
 
25
+ def lower_bound
26
+ case lower_bound_type
27
+ when Types::ClassInstance, Types::ClassSingleton, Types::Interface
28
+ lower_bound_type
29
+ end
30
+ end
31
+
24
32
  def unchecked!(value = true)
25
33
  @unchecked = value ? true : false
26
34
  self
@@ -35,6 +43,7 @@ module RBS
35
43
  other.name == name &&
36
44
  other.variance == variance &&
37
45
  other.upper_bound_type == upper_bound_type &&
46
+ other.lower_bound_type == lower_bound_type &&
38
47
  other.default_type == default_type &&
39
48
  other.unchecked? == unchecked?
40
49
  end
@@ -42,7 +51,7 @@ module RBS
42
51
  alias eql? ==
43
52
 
44
53
  def hash
45
- self.class.hash ^ name.hash ^ variance.hash ^ upper_bound_type.hash ^ unchecked?.hash ^ default_type.hash
54
+ self.class.hash ^ name.hash ^ variance.hash ^ upper_bound_type.hash ^ lower_bound_type.hash ^ unchecked?.hash ^ default_type.hash
46
55
  end
47
56
 
48
57
  def to_json(state = JSON::State.new)
@@ -52,6 +61,7 @@ module RBS
52
61
  unchecked: unchecked?,
53
62
  location: location,
54
63
  upper_bound: upper_bound_type,
64
+ lower_bound: lower_bound_type,
55
65
  default_type: default_type
56
66
  }.to_json(state)
57
67
  end
@@ -61,6 +71,10 @@ module RBS
61
71
  _upper_bound_type = yield(b)
62
72
  end
63
73
 
74
+ if b = lower_bound_type
75
+ _lower_bound_type = yield(b)
76
+ end
77
+
64
78
  if dt = default_type
65
79
  _default_type = yield(dt)
66
80
  end
@@ -69,6 +83,7 @@ module RBS
69
83
  name: name,
70
84
  variance: variance,
71
85
  upper_bound: _upper_bound_type,
86
+ lower_bound: _lower_bound_type,
72
87
  location: location,
73
88
  default_type: _default_type
74
89
  ).unchecked!(unchecked?)
@@ -108,6 +123,7 @@ module RBS
108
123
  name: new_name,
109
124
  variance: param.variance,
110
125
  upper_bound: param.upper_bound_type&.map_type {|type| type.sub(subst) },
126
+ lower_bound: param.lower_bound_type&.map_type {|type| type.sub(subst) },
111
127
  location: param.location,
112
128
  default_type: param.default_type&.map_type {|type| type.sub(subst) }
113
129
  ).unchecked!(param.unchecked?)
@@ -136,6 +152,10 @@ module RBS
136
152
  s << " < #{type}"
137
153
  end
138
154
 
155
+ if type = lower_bound_type
156
+ s << " > #{type}"
157
+ end
158
+
139
159
  if dt = default_type
140
160
  s << " = #{dt}"
141
161
  end
@@ -176,7 +196,7 @@ module RBS
176
196
  end
177
197
 
178
198
  def self.normalize_args(params, args)
179
- app = application(params, args) or return []
199
+ app = application(params, args) or return args
180
200
 
181
201
  min_count = params.count { _1.default_type.nil? }
182
202
  unless min_count <= args.size && args.size <= params.size
data/lib/rbs/buffer.rb CHANGED
@@ -29,19 +29,24 @@ module RBS
29
29
 
30
30
  def ranges
31
31
  @ranges ||= begin
32
- lines = content.lines
33
- lines << "" if content.end_with?("\n")
34
-
35
- ranges = [] #: Array[Range[Integer]]
36
- offset = 0
37
-
38
- lines.each do |line|
39
- size0 = line.size
40
- line = line.chomp
41
- range = offset...(offset+line.size)
42
- ranges << range
43
-
44
- offset += size0
32
+ if content.empty?
33
+ ranges = [0...0] #: Array[Range[Integer]]
34
+ lines = [""]
35
+ else
36
+ lines = content.lines
37
+ lines << "" if content.end_with?("\n")
38
+
39
+ ranges = [] #: Array[Range[Integer]]
40
+ offset = 0
41
+
42
+ lines.each do |line|
43
+ size0 = line.size
44
+ line = line.chomp
45
+ range = offset...(offset+line.size)
46
+ ranges << range
47
+
48
+ offset += size0
49
+ end
45
50
  end
46
51
 
47
52
  ranges
@@ -84,9 +89,9 @@ module RBS
84
89
 
85
90
  def rbs_location(location, loc2=nil)
86
91
  if loc2
87
- Location.new(self, location.start_character_offset, loc2.end_character_offset)
92
+ Location.new(self.top_buffer, location.start_character_offset, loc2.end_character_offset)
88
93
  else
89
- Location.new(self, location.start_character_offset, location.end_character_offset)
94
+ Location.new(self.top_buffer, location.start_character_offset, location.end_character_offset)
90
95
  end
91
96
  end
92
97
 
data/lib/rbs/cli/diff.rb CHANGED
@@ -3,13 +3,14 @@
3
3
  module RBS
4
4
  class CLI
5
5
  class Diff
6
- def initialize(argv:, library_options:, stdout: $stdout, stderr: $stderr)
7
- @format = nil
6
+ def initialize(stdout: $stdout, stderr: $stderr)
8
7
  @stdout = stdout
9
8
  @stderr = stderr
9
+ end
10
10
 
11
- # @type var type_name: String?
12
- type_name = nil
11
+ def run(argv:, library_options:)
12
+ format = nil #: String?
13
+ type_name = nil #: String?
13
14
  library_options = library_options
14
15
  before_path = [] #: Array[String]
15
16
  after_path = [] #: Array[String]
@@ -32,7 +33,7 @@ module RBS
32
33
  # Confirmation of methods related to Time class added by including stdlib/time
33
34
  $ rbs diff --format diff --type-name Time --after stdlib/time
34
35
  HELP
35
- o.on("--format NAME") { |arg| @format = arg }
36
+ o.on("--format NAME") { |arg| format = arg }
36
37
  o.on("--type-name NAME") { |arg| type_name = arg }
37
38
  o.on("--before DIR") { |arg| before_path << arg }
38
39
  o.on("--after DIR") { |arg| after_path << arg }
@@ -40,28 +41,28 @@ module RBS
40
41
  end
41
42
  opt.parse!(argv)
42
43
 
43
- unless @format && type_name && ["markdown", "diff"].include?(@format)
44
+ unless format && type_name && ["markdown", "diff"].include?(format)
44
45
  @stderr.puts opt.banner
45
- exit 1
46
+ return 1
46
47
  end
47
48
 
48
- @diff = RBS::Diff.new(
49
+ diff = RBS::Diff.new(
49
50
  type_name: TypeName.parse(type_name).absolute!,
50
51
  library_options: library_options,
51
52
  after_path: after_path,
52
53
  before_path: before_path,
53
54
  detail: detail,
54
55
  )
55
- end
56
56
 
57
- def run
58
- public_send("run_#{@format}")
57
+ public_send("run_#{format}", diff)
58
+
59
+ 0
59
60
  end
60
61
 
61
- def run_diff
62
+ def run_diff(diff)
62
63
  first = true
63
64
  io = RBS::CLI::ColoredIO.new(stdout: @stdout)
64
- @diff.each_diff do |before, after|
65
+ diff.each_diff do |before, after|
65
66
  io.puts if !first
66
67
  io.puts_red "- #{before}"
67
68
  io.puts_green "+ #{after}"
@@ -69,10 +70,10 @@ module RBS
69
70
  end
70
71
  end
71
72
 
72
- def run_markdown
73
+ def run_markdown(diff)
73
74
  @stdout.puts "| before | after |"
74
75
  @stdout.puts "| --- | --- |"
75
- @diff.each_diff do |before, after|
76
+ diff.each_diff do |before, after|
76
77
  before.gsub!("|", "\\|")
77
78
  after.gsub!("|", "\\|")
78
79
  @stdout.puts "| `#{before}` | `#{after}` |"