rbs 3.5.3 → 3.6.0.dev.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependabot.yml +5 -1
  3. data/.github/workflows/ruby.yml +2 -18
  4. data/.github/workflows/windows.yml +26 -0
  5. data/CHANGELOG.md +0 -18
  6. data/core/array.rbs +10 -10
  7. data/core/basic_object.rbs +3 -3
  8. data/core/enumerable.rbs +6 -0
  9. data/core/enumerator.rbs +7 -0
  10. data/core/fiber.rbs +1 -1
  11. data/core/global_variables.rbs +2 -2
  12. data/core/kernel.rbs +67 -38
  13. data/core/method.rbs +98 -7
  14. data/core/module.rbs +2 -2
  15. data/core/proc.rbs +184 -23
  16. data/core/ractor.rbs +1 -1
  17. data/core/range.rbs +30 -0
  18. data/core/refinement.rbs +16 -26
  19. data/core/symbol.rbs +34 -26
  20. data/core/thread.rbs +2 -2
  21. data/core/trace_point.rbs +12 -12
  22. data/core/unbound_method.rbs +1 -1
  23. data/docs/syntax.md +21 -9
  24. data/ext/rbs_extension/parser.c +119 -51
  25. data/ext/rbs_extension/ruby_objs.c +2 -1
  26. data/ext/rbs_extension/ruby_objs.h +1 -1
  27. data/lib/rbs/ast/declarations.rb +36 -0
  28. data/lib/rbs/ast/type_param.rb +71 -15
  29. data/lib/rbs/ast/visitor.rb +137 -0
  30. data/lib/rbs/cli/validate.rb +41 -7
  31. data/lib/rbs/cli.rb +3 -3
  32. data/lib/rbs/definition.rb +2 -1
  33. data/lib/rbs/definition_builder/ancestor_builder.rb +30 -4
  34. data/lib/rbs/definition_builder.rb +21 -6
  35. data/lib/rbs/environment_loader.rb +1 -1
  36. data/lib/rbs/errors.rb +7 -2
  37. data/lib/rbs/file_finder.rb +9 -12
  38. data/lib/rbs/locator.rb +8 -5
  39. data/lib/rbs/prototype/rbi.rb +2 -1
  40. data/lib/rbs/prototype/runtime.rb +3 -2
  41. data/lib/rbs/sorter.rb +9 -6
  42. data/lib/rbs/test/type_check.rb +6 -0
  43. data/lib/rbs/types.rb +11 -0
  44. data/lib/rbs/validator.rb +2 -2
  45. data/lib/rbs/vendorer.rb +3 -3
  46. data/lib/rbs/version.rb +1 -1
  47. data/lib/rbs.rb +1 -0
  48. data/sig/declarations.rbs +6 -0
  49. data/sig/definition.rbs +1 -1
  50. data/sig/definition_builder.rbs +3 -1
  51. data/sig/errors.rbs +3 -2
  52. data/sig/file_finder.rbs +24 -2
  53. data/sig/method_types.rbs +1 -1
  54. data/sig/sorter.rbs +1 -1
  55. data/sig/type_param.rbs +41 -9
  56. data/sig/types.rbs +12 -0
  57. data/sig/visitor.rbs +47 -0
  58. data/stdlib/csv/0/csv.rbs +27 -0
  59. data/stdlib/net-http/0/net-http.rbs +1 -1
  60. data/stdlib/zlib/0/gzip_reader.rbs +5 -1
  61. metadata +5 -2
data/core/thread.rbs CHANGED
@@ -382,7 +382,7 @@ class Thread < Object
382
382
  # If you're going to subclass Thread, be sure to call super in your `initialize`
383
383
  # method, otherwise a ThreadError will be raised.
384
384
  #
385
- def initialize: (*untyped) { (*untyped) -> void } -> void
385
+ def initialize: (*untyped) { (?) -> void } -> void
386
386
 
387
387
  # <!--
388
388
  # rdoc-file=thread.c
@@ -1178,7 +1178,7 @@ class Thread < Object
1178
1178
  # calling `start` in that subclass will not invoke the subclass's `initialize`
1179
1179
  # method.
1180
1180
  #
1181
- def self.start: (*untyped args) { (*untyped) -> void } -> instance
1181
+ def self.start: (*untyped args) { (?) -> void } -> instance
1182
1182
 
1183
1183
  # <!--
1184
1184
  # rdoc-file=thread.c
data/core/trace_point.rbs CHANGED
@@ -63,7 +63,7 @@
63
63
  # `:script_compiled`
64
64
  # : new Ruby code compiled (with `eval`, `load` or `require`)
65
65
  #
66
- class TracePoint < Object
66
+ class TracePoint
67
67
  # <!--
68
68
  # rdoc-file=trace_point.rb
69
69
  # - TracePoint.new(*events) { |obj| block } -> obj
@@ -110,7 +110,7 @@ class TracePoint < Object
110
110
  #
111
111
  # Access from other threads is also forbidden.
112
112
  #
113
- def initialize: (*Symbol events) { (TracePoint tp) -> void } -> void
113
+ def self.new: (*_ToSym events) { (instance tp) -> void } -> instance
114
114
 
115
115
  # <!--
116
116
  # rdoc-file=trace_point.rb
@@ -172,7 +172,7 @@ class TracePoint < Object
172
172
  # (note that we needed to filter out calls by itself from :line handler,
173
173
  # otherwise it will call itself infinitely).
174
174
  #
175
- def self.allow_reentry: () { () -> void } -> void
175
+ def self.allow_reentry: [T] () { (nil) -> T } -> T
176
176
 
177
177
  # <!--
178
178
  # rdoc-file=trace_point.rb
@@ -199,7 +199,7 @@ class TracePoint < Object
199
199
  #
200
200
  # trace.enabled? #=> true
201
201
  #
202
- def self.trace: (*Symbol events) { (TracePoint tp) -> void } -> TracePoint
202
+ def self.trace: (*_ToSym events) { (instance tp) -> void } -> instance
203
203
 
204
204
  # <!--
205
205
  # rdoc-file=trace_point.rb
@@ -218,7 +218,7 @@ class TracePoint < Object
218
218
  # -->
219
219
  # Return the called name of the method being called
220
220
  #
221
- def callee_id: () -> Symbol
221
+ def callee_id: () -> Symbol?
222
222
 
223
223
  # <!--
224
224
  # rdoc-file=trace_point.rb
@@ -257,7 +257,7 @@ class TracePoint < Object
257
257
  # C.foo
258
258
  # end
259
259
  #
260
- def defined_class: () -> Module
260
+ def defined_class: () -> (Class | Module)?
261
261
 
262
262
  # <!--
263
263
  # rdoc-file=trace_point.rb
@@ -293,7 +293,7 @@ class TracePoint < Object
293
293
  # #=> RuntimeError: access from outside
294
294
  #
295
295
  def disable: () -> bool
296
- | () { () -> void } -> void
296
+ | [T] () { () -> T } -> T
297
297
 
298
298
  # <!--
299
299
  # rdoc-file=trace_point.rb
@@ -352,8 +352,8 @@ class TracePoint < Object
352
352
  # trace.enable { p tp.lineno }
353
353
  # #=> RuntimeError: access from outside
354
354
  #
355
- def enable: (?target: (Method | UnboundMethod | Proc)?, ?target_line: Integer?, ?target_thread: Thread?) -> bool
356
- | [R] (?target: (Method | UnboundMethod | Proc)?, ?target_line: Integer?, ?target_thread: Thread?) { () -> R } -> R
355
+ def enable: (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) -> bool
356
+ | [T] (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) { () -> T } -> T
357
357
 
358
358
  # <!--
359
359
  # rdoc-file=trace_point.rb
@@ -395,7 +395,7 @@ class TracePoint < Object
395
395
  # -->
396
396
  # Return the name at the definition of the method being called
397
397
  #
398
- def method_id: () -> Symbol
398
+ def method_id: () -> Symbol?
399
399
 
400
400
  # <!--
401
401
  # rdoc-file=trace_point.rb
@@ -412,7 +412,7 @@ class TracePoint < Object
412
412
  # Return the parameters definition of the method or block that the current hook
413
413
  # belongs to. Format is the same as for Method#parameters
414
414
  #
415
- def parameters: () -> ::Array[[ :req | :opt | :rest | :keyreq | :key | :keyrest | :block, Symbol ] | [ :rest | :keyrest ]]
415
+ def parameters: () -> Method::param_types?
416
416
 
417
417
  # <!--
418
418
  # rdoc-file=trace_point.rb
@@ -421,7 +421,7 @@ class TracePoint < Object
421
421
  # Value from exception raised on the `:raise` event, or rescued on the `:rescue`
422
422
  # event.
423
423
  #
424
- def raised_exception: () -> untyped
424
+ def raised_exception: () -> Exception
425
425
 
426
426
  # <!--
427
427
  # rdoc-file=trace_point.rb
@@ -325,5 +325,5 @@ class UnboundMethod
325
325
  # arguments. This is semantically equivalent to `umeth.bind(recv).call(args,
326
326
  # ...)`.
327
327
  #
328
- def bind_call: (untyped recv, *untyped, **untyped) ?{ (*untyped, **untyped) -> untyped } -> untyped
328
+ def bind_call: (untyped recv, *untyped, **untyped) ?{ (?) -> untyped } -> untyped
329
329
  end
data/docs/syntax.md CHANGED
@@ -64,7 +64,7 @@ Interface type denotes _type of a value which can be a subtype of the interface_
64
64
 
65
65
  ```rbs
66
66
  _ToS # _ToS interface
67
- ::MyApp::_Each[String] # Interface name with namespace and type application
67
+ ::Enumerator::_Each[String] # Interface name with namespace and type application
68
68
  ```
69
69
 
70
70
  ### Alias type
@@ -750,16 +750,15 @@ $LOAD_PATH: Array[String]
750
750
  ### Generics
751
751
 
752
752
  ```markdown
753
- _module-type-parameter_ ::= _generics-unchecked_ _generics-variance_ _type-variable_ _generics-bound_
753
+ _module-type-parameter_ ::= _generics-unchecked_ _generics-variance_ _type-variable_ _generics-bound_ _default-type_
754
754
 
755
755
  _method-type-param_ ::= _type-variable_ _generics-bound_
756
756
 
757
- _generics-bound_ ::= (No type bound)
758
- | `<` _bound-type_ (The generics parameter is bounded)
757
+ _generics-bound_ ::= (No type bound)
758
+ | `<` _type_ (The generics parameter is bounded)
759
759
 
760
- _bound-type_ ::= _class-name_ _type-arguments_ (Class instance type)
761
- | _interface-name_ _type-arguments_ (Interface type)
762
- | `singleton(` _class-name_ `)` (Class singleton type)
760
+ _default-type_ ::= (No default type)
761
+ | `=` _type_ (The generics parameter has default type)
763
762
 
764
763
  _generics-variance_ ::= (Invariant)
765
764
  | `out` (Covariant)
@@ -826,14 +825,27 @@ class PrettyPrint[T < _Output]
826
825
  end
827
826
  ```
828
827
 
829
- If a type parameter has an upper bound, the type parameter must be instantiated with types that is a subclass of the upper bound.
828
+ If a type parameter has an upper bound, the type parameter must be instantiated with types that is a subtype of the upper bound.
830
829
 
831
830
  ```rbs
832
831
  type str_printer = PrettyPrint[String] # OK
833
832
  type int_printer = PrettyPrint[Integer] # Type error
834
833
  ```
835
834
 
836
- The upper bound must be one of a class instance type, interface type, or class singleton type.
835
+ The generics type parameter of modules, classes, interfaces, or type aliases can have a default type.
836
+
837
+ ```rbs
838
+ interface _Foo[T = untyped]
839
+ end
840
+
841
+ interface _Bar[T, S = untyped]
842
+ end
843
+
844
+ type foo = _Foo # equivalent to _Foo[untyped]
845
+ type bar = _Bar[String] # equivalent to _Bar[String, untyped]
846
+ ```
847
+
848
+ Type parameters with default types cannot appear before type parameters without default types. The generic method type parameters cannot have the default types.
837
849
 
838
850
  ### Directives
839
851