rbs 3.3.2 → 3.4.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -5
  3. data/.github/workflows/ruby.yml +7 -8
  4. data/.github/workflows/typecheck.yml +37 -0
  5. data/CHANGELOG.md +50 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +11 -11
  8. data/Steepfile +2 -2
  9. data/core/array.rbs +19 -49
  10. data/core/basic_object.rbs +2 -2
  11. data/core/comparable.rbs +17 -8
  12. data/core/complex.rbs +82 -43
  13. data/core/data.rbs +2 -4
  14. data/core/dir.rbs +635 -295
  15. data/core/enumerable.rbs +11 -18
  16. data/core/enumerator.rbs +37 -31
  17. data/core/errors.rbs +4 -0
  18. data/core/false_class.rbs +34 -15
  19. data/core/fiber.rbs +23 -0
  20. data/core/file.rbs +329 -120
  21. data/core/float.rbs +17 -32
  22. data/core/gc.rbs +17 -11
  23. data/core/hash.rbs +22 -44
  24. data/core/integer.rbs +82 -113
  25. data/core/io/buffer.rbs +90 -47
  26. data/core/io.rbs +39 -116
  27. data/core/kernel.rbs +442 -489
  28. data/core/match_data.rbs +55 -56
  29. data/core/module.rbs +45 -1
  30. data/core/nil_class.rbs +98 -35
  31. data/core/numeric.rbs +22 -32
  32. data/core/object_space/weak_key_map.rbs +102 -0
  33. data/core/process.rbs +1242 -655
  34. data/core/ractor.rbs +139 -120
  35. data/core/range.rbs +100 -4
  36. data/core/rational.rbs +0 -4
  37. data/core/rbs/unnamed/argf.rbs +16 -8
  38. data/core/rbs/unnamed/env_class.rbs +0 -24
  39. data/core/refinement.rbs +8 -0
  40. data/core/regexp.rbs +1149 -598
  41. data/core/ruby_vm.rbs +126 -12
  42. data/core/rubygems/platform.rbs +9 -0
  43. data/core/rubygems/rubygems.rbs +1 -1
  44. data/core/rubygems/version.rbs +5 -1
  45. data/core/set.rbs +20 -22
  46. data/core/signal.rbs +4 -4
  47. data/core/string.rbs +283 -230
  48. data/core/string_io.rbs +2 -14
  49. data/core/struct.rbs +404 -24
  50. data/core/symbol.rbs +1 -19
  51. data/core/thread.rbs +29 -12
  52. data/core/time.rbs +227 -104
  53. data/core/trace_point.rbs +2 -5
  54. data/core/true_class.rbs +54 -21
  55. data/core/warning.rbs +14 -11
  56. data/docs/data_and_struct.md +29 -0
  57. data/docs/syntax.md +3 -5
  58. data/docs/tools.md +1 -0
  59. data/ext/rbs_extension/lexer.c +643 -559
  60. data/ext/rbs_extension/lexer.re +5 -1
  61. data/ext/rbs_extension/parser.c +12 -3
  62. data/ext/rbs_extension/unescape.c +7 -47
  63. data/lib/rbs/cli/diff.rb +4 -1
  64. data/lib/rbs/cli/validate.rb +280 -0
  65. data/lib/rbs/cli.rb +2 -194
  66. data/lib/rbs/collection/config.rb +5 -6
  67. data/lib/rbs/collection/sources/git.rb +1 -1
  68. data/lib/rbs/collection.rb +1 -0
  69. data/lib/rbs/diff.rb +7 -4
  70. data/lib/rbs/errors.rb +11 -0
  71. data/lib/rbs/test/errors.rb +4 -1
  72. data/lib/rbs/test/guaranteed.rb +2 -3
  73. data/lib/rbs/test/type_check.rb +15 -10
  74. data/lib/rbs/test.rb +3 -3
  75. data/lib/rbs/types.rb +29 -0
  76. data/lib/rbs/unit_test/convertibles.rb +176 -0
  77. data/lib/rbs/unit_test/spy.rb +136 -0
  78. data/lib/rbs/unit_test/type_assertions.rb +341 -0
  79. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  80. data/lib/rbs/unit_test.rb +6 -0
  81. data/lib/rbs/version.rb +1 -1
  82. data/sig/cli/validate.rbs +43 -0
  83. data/sig/diff.rbs +3 -1
  84. data/sig/errors.rbs +8 -0
  85. data/sig/rbs.rbs +1 -1
  86. data/sig/test/errors.rbs +52 -0
  87. data/sig/test/guranteed.rbs +9 -0
  88. data/sig/test/type_check.rbs +19 -0
  89. data/sig/test.rbs +82 -0
  90. data/sig/types.rbs +6 -1
  91. data/sig/unit_test/convertibles.rbs +154 -0
  92. data/sig/unit_test/spy.rbs +28 -0
  93. data/sig/unit_test/type_assertions.rbs +194 -0
  94. data/sig/unit_test/with_aliases.rbs +136 -0
  95. data/stdlib/base64/0/base64.rbs +307 -45
  96. data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
  97. data/stdlib/coverage/0/coverage.rbs +2 -2
  98. data/stdlib/csv/0/csv.rbs +25 -55
  99. data/stdlib/date/0/date.rbs +1 -43
  100. data/stdlib/date/0/date_time.rbs +1 -13
  101. data/stdlib/delegate/0/delegator.rbs +186 -0
  102. data/stdlib/delegate/0/kernel.rbs +47 -0
  103. data/stdlib/delegate/0/simple_delegator.rbs +98 -0
  104. data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
  105. data/stdlib/erb/0/erb.rbs +2 -2
  106. data/stdlib/fileutils/0/fileutils.rbs +0 -19
  107. data/stdlib/io-console/0/io-console.rbs +12 -1
  108. data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
  109. data/stdlib/json/0/json.rbs +320 -81
  110. data/stdlib/logger/0/logger.rbs +9 -5
  111. data/stdlib/monitor/0/monitor.rbs +78 -0
  112. data/stdlib/net-http/0/net-http.rbs +1880 -543
  113. data/stdlib/objspace/0/objspace.rbs +19 -13
  114. data/stdlib/openssl/0/openssl.rbs +508 -127
  115. data/stdlib/optparse/0/optparse.rbs +25 -11
  116. data/stdlib/pathname/0/pathname.rbs +1 -1
  117. data/stdlib/pp/0/pp.rbs +2 -5
  118. data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
  119. data/stdlib/pstore/0/pstore.rbs +2 -4
  120. data/stdlib/rdoc/0/comment.rbs +1 -2
  121. data/stdlib/resolv/0/resolv.rbs +4 -2
  122. data/stdlib/socket/0/socket.rbs +2 -2
  123. data/stdlib/socket/0/unix_socket.rbs +2 -2
  124. data/stdlib/strscan/0/string_scanner.rbs +3 -2
  125. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  126. data/stdlib/uri/0/common.rbs +245 -123
  127. metadata +23 -4
  128. data/lib/rbs/test/spy.rb +0 -6
data/core/enumerable.rbs CHANGED
@@ -5,7 +5,8 @@
5
5
  #
6
6
  # * [Querying](rdoc-ref:Enumerable@Methods+for+Querying)
7
7
  # * [Fetching](rdoc-ref:Enumerable@Methods+for+Fetching)
8
- # * [Searching](rdoc-ref:Enumerable@Methods+for+Searching)
8
+ # * [Searching and
9
+ # Filtering](rdoc-ref:Enumerable@Methods+for+Searching+and+Filtering)
9
10
  # * [Sorting](rdoc-ref:Enumerable@Methods+for+Sorting)
10
11
  # * [Iterating](rdoc-ref:Enumerable@Methods+for+Iterating)
11
12
  # * [And more....](rdoc-ref:Enumerable@Other+Methods)
@@ -210,6 +211,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
210
211
  # -->
211
212
  # Returns whether every element meets a given criterion.
212
213
  #
214
+ # If `self` has no element, returns `true` and argument or block are not used.
215
+ #
213
216
  # With no argument and no block, returns whether every element is truthy:
214
217
  #
215
218
  # (1..4).all? # => true
@@ -252,6 +255,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
252
255
  # -->
253
256
  # Returns whether any element meets a given criterion.
254
257
  #
258
+ # If `self` has no element, returns `false` and argument or block are not used.
259
+ #
255
260
  # With no argument and no block, returns whether any element is truthy:
256
261
  #
257
262
  # (1..4).any? # => true
@@ -521,8 +526,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
521
526
  #
522
527
  # (0..4).to_a # => [0, 1, 2, 3, 4]
523
528
  #
524
- # Enumerable#entries is an alias for Enumerable#to_a.
525
- #
526
529
  def entries: () -> ::Array[Elem]
527
530
 
528
531
  # <!--
@@ -721,8 +724,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
721
724
  # {foo: 0, bar: 1, baz: 2}.include?('foo') # => false
722
725
  # {foo: 0, bar: 1, baz: 2}.include?(0) # => false
723
726
  #
724
- # Enumerable#member? is an alias for Enumerable#include?.
725
- #
726
727
  def include?: (Elem arg0) -> bool
727
728
 
728
729
  # <!--
@@ -874,8 +875,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
874
875
  # "Memo: 3; element: 3"
875
876
  # "Memo: 6; element: 4"
876
877
  #
877
- # Enumerable#reduce is an alias for Enumerable#inject.
878
- #
879
878
  def inject: (untyped init, Symbol method) -> untyped
880
879
  | (Symbol method) -> untyped
881
880
  | [A] (A initial) { (A, Elem) -> A } -> A
@@ -1446,8 +1445,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
1446
1445
 
1447
1446
  # <!--
1448
1447
  # rdoc-file=enum.c
1449
- # - to_h -> hash
1450
- # - to_h {|element| ... } -> hash
1448
+ # - to_h(*args) -> hash
1449
+ # - to_h(*args) {|element| ... } -> hash
1451
1450
  # -->
1452
1451
  # When `self` consists of 2-element arrays, returns a hash each of whose entries
1453
1452
  # is the key-value pair formed from one of those arrays:
@@ -1570,8 +1569,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
1570
1569
  # {foo: 0, bar: 1, baz: 2}.include?('foo') # => false
1571
1570
  # {foo: 0, bar: 1, baz: 2}.include?(0) # => false
1572
1571
  #
1573
- # Enumerable#member? is an alias for Enumerable#include?.
1574
- #
1575
1572
  def member?: (Elem arg0) -> bool
1576
1573
 
1577
1574
  # <!-- rdoc-file=enum.c -->
@@ -1717,20 +1714,16 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
1717
1714
  # "Memo: 3; element: 3"
1718
1715
  # "Memo: 6; element: 4"
1719
1716
  #
1720
- # Enumerable#reduce is an alias for Enumerable#inject.
1721
- #
1722
1717
  alias reduce inject
1723
1718
 
1724
1719
  # <!--
1725
1720
  # rdoc-file=enum.c
1726
- # - to_a -> array
1721
+ # - to_a(*args) -> array
1727
1722
  # -->
1728
1723
  # Returns an array containing the items in `self`:
1729
1724
  #
1730
1725
  # (0..4).to_a # => [0, 1, 2, 3, 4]
1731
1726
  #
1732
- # Enumerable#entries is an alias for Enumerable#to_a.
1733
- #
1734
1727
  def to_a: () -> ::Array[Elem]
1735
1728
 
1736
1729
  # <!--
@@ -1774,8 +1767,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
1774
1767
  # %w[a b c c b a a b c].uniq # => ["a", "b", "c"]
1775
1768
  # [0, 1, 2, 2, 1, 0, 0, 1, 2].uniq # => [0, 1, 2]
1776
1769
  #
1777
- # With a block, returns a new array containing only for which the block returns
1778
- # a unique value:
1770
+ # With a block, returns a new array containing elements only for which the block
1771
+ # returns a unique value:
1779
1772
  #
1780
1773
  # a = [0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]
1781
1774
  # a.uniq {|i| i.even? ? i : 0 } # => [0, 2, 4]
data/core/enumerator.rbs CHANGED
@@ -37,10 +37,10 @@
37
37
  # list's elements to strings containing the index and the element as a string
38
38
  # via:
39
39
  #
40
- # puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" }
41
- # # => ["0:foo", "1:bar", "2:baz"]
40
+ # puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" }
41
+ # # => ["0:foo", "1:bar", "2:baz"]
42
42
  #
43
- # == External Iteration
43
+ # ## External Iteration
44
44
  #
45
45
  # An Enumerator can also be used as an external iterator. For example,
46
46
  # Enumerator#next returns the next value of the iterator or raises StopIteration
@@ -52,42 +52,48 @@
52
52
  # puts e.next # => 3
53
53
  # puts e.next # raises StopIteration
54
54
  #
55
- # `next`, `next_values`, `peek` and `peek_values` are the only methods which use
56
- # external iteration (and Array#zip(Enumerable-not-Array) which uses `next`).
55
+ # `next`, `next_values`, `peek`, and `peek_values` are the only methods which
56
+ # use external iteration (and Array#zip(Enumerable-not-Array) which uses `next`
57
+ # internally).
57
58
  #
58
59
  # These methods do not affect other internal enumeration methods, unless the
59
60
  # underlying iteration method itself has side-effect, e.g. IO#each_line.
60
61
  #
62
+ # FrozenError will be raised if these methods are called against a frozen
63
+ # enumerator. Since `rewind` and `feed` also change state for external
64
+ # iteration, these methods may raise FrozenError too.
65
+ #
61
66
  # External iteration differs **significantly** from internal iteration due to
62
67
  # using a Fiber:
63
- # - The Fiber adds some overhead compared to internal enumeration.
64
- # - The stacktrace will only include the stack from the Enumerator, not above.
65
- # - Fiber-local variables are *not* inherited inside the Enumerator Fiber,
66
- # which instead starts with no Fiber-local variables.
67
- # - Fiber storage variables *are* inherited and are designed
68
- # to handle Enumerator Fibers. Assigning to a Fiber storage variable
69
- # only affects the current Fiber, so if you want to change state
70
- # in the caller Fiber of the Enumerator Fiber, you need to use an
71
- # extra indirection (e.g., use some object in the Fiber storage
72
- # variable and mutate some ivar of it).
68
+ # * The Fiber adds some overhead compared to internal enumeration.
69
+ # * The stacktrace will only include the stack from the Enumerator, not above.
70
+ # * Fiber-local variables are **not** inherited inside the Enumerator Fiber,
71
+ # which instead starts with no Fiber-local variables.
72
+ # * Fiber storage variables **are** inherited and are designed to handle
73
+ # Enumerator Fibers. Assigning to a Fiber storage variable only affects the
74
+ # current Fiber, so if you want to change state in the caller Fiber of the
75
+ # Enumerator Fiber, you need to use an extra indirection (e.g., use some
76
+ # object in the Fiber storage variable and mutate some ivar of it).
77
+ #
73
78
  #
74
79
  # Concretely:
75
- # Thread.current[:fiber_local] = 1
76
- # Fiber[:storage_var] = 1
77
- # e = Enumerator.new do |y|
78
- # p Thread.current[:fiber_local] # for external iteration: nil, for internal iteration: 1
79
- # p Fiber[:storage_var] # => 1, inherited
80
- # Fiber[:storage_var] += 1
81
- # y << 42
82
- # end
83
- #
84
- # p e.next # => 42
85
- # p Fiber[:storage_var] # => 1 (it ran in a different Fiber)
86
- #
87
- # e.each { p _1 }
88
- # p Fiber[:storage_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber)
89
- #
90
- # == Convert External Iteration to Internal Iteration
80
+ #
81
+ # Thread.current[:fiber_local] = 1
82
+ # Fiber[:storage_var] = 1
83
+ # e = Enumerator.new do |y|
84
+ # p Thread.current[:fiber_local] # for external iteration: nil, for internal iteration: 1
85
+ # p Fiber[:storage_var] # => 1, inherited
86
+ # Fiber[:storage_var] += 1
87
+ # y << 42
88
+ # end
89
+ #
90
+ # p e.next # => 42
91
+ # p Fiber[:storage_var] # => 1 (it ran in a different Fiber)
92
+ #
93
+ # e.each { p _1 }
94
+ # p Fiber[:storage_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber)
95
+ #
96
+ # ## Convert External Iteration to Internal Iteration
91
97
  #
92
98
  # You can use an external iterator to implement an internal iterator as follows:
93
99
  #
data/core/errors.rbs CHANGED
@@ -188,6 +188,10 @@ end
188
188
  #
189
189
  # LoadError: no such file to load -- this/file/does/not/exist
190
190
  #
191
+ # <!-- rdoc-file=lib/bundled_gems.rb -->
192
+ # for RubyGems without Bundler environment. If loading library is not part of
193
+ # the default gems and the bundled gems, warn it.
194
+ #
191
195
  class LoadError < ScriptError
192
196
  # <!-- rdoc-file=error.c -->
193
197
  # the path failed to load
data/core/false_class.rbs CHANGED
@@ -8,32 +8,47 @@ class FalseClass
8
8
 
9
9
  # <!--
10
10
  # rdoc-file=object.c
11
- # - false & obj -> false
12
- # - nil & obj -> false
11
+ # - false & object -> false
12
+ # - nil & object -> false
13
13
  # -->
14
- # And---Returns `false`. *obj* is always evaluated as it is the argument to a
15
- # method call---there is no short-circuit evaluation in this case.
14
+ # Returns `false`:
15
+ #
16
+ # false & true # => false
17
+ # false & Object.new # => false
18
+ #
19
+ # Argument `object` is evaluated:
20
+ #
21
+ # false & raise # Raises RuntimeError.
16
22
  #
17
23
  def &: (untyped obj) -> false
18
24
 
19
25
  # <!--
20
26
  # rdoc-file=object.c
21
- # - obj === other -> true or false
27
+ # - true === other -> true or false
28
+ # - false === other -> true or false
29
+ # - nil === other -> true or false
22
30
  # -->
23
- # Case Equality -- For class Object, effectively the same as calling `#==`, but
24
- # typically overridden by descendants to provide meaningful semantics in `case`
25
- # statements.
31
+ # Returns `true` or `false`.
32
+ #
33
+ # Like Object#==, if `object` is an instance of Object (and not an instance of
34
+ # one of its many subclasses).
35
+ #
36
+ # This method is commonly overridden by those subclasses, to provide meaningful
37
+ # semantics in `case` statements.
26
38
  #
27
39
  def ===: (false) -> true
28
40
  | (untyped obj) -> bool
29
41
 
30
42
  # <!--
31
43
  # rdoc-file=object.c
32
- # - false ^ obj -> true or false
33
- # - nil ^ obj -> true or false
44
+ # - false ^ object -> true or false
45
+ # - nil ^ object -> true or false
34
46
  # -->
35
- # Exclusive Or---If *obj* is `nil` or `false`, returns `false`; otherwise,
36
- # returns `true`.
47
+ # Returns `false` if `object` is `nil` or `false`, `true` otherwise:
48
+ #
49
+ # nil ^ nil # => false
50
+ # nil ^ false # => false
51
+ # nil ^ Object.new # => true
37
52
  #
38
53
  def ^: (false | nil) -> false
39
54
  | (untyped obj) -> bool
@@ -53,10 +68,14 @@ class FalseClass
53
68
 
54
69
  # <!--
55
70
  # rdoc-file=object.c
56
- # - false | obj -> true or false
57
- # - nil | obj -> true or false
71
+ # - false | object -> true or false
72
+ # - nil | object -> true or false
58
73
  # -->
59
- # Or---Returns `false` if *obj* is `nil` or `false`; `true` otherwise.
74
+ # Returns `false` if `object` is `nil` or `false`, `true` otherwise:
75
+ #
76
+ # nil | nil # => false
77
+ # nil | false # => false
78
+ # nil | Object.new # => true
60
79
  #
61
80
  def |: (nil | false) -> false
62
81
  | (untyped obj) -> bool
data/core/fiber.rbs CHANGED
@@ -369,6 +369,27 @@ class Fiber < Object
369
369
  #
370
370
  alias inspect to_s
371
371
 
372
+ # <!--
373
+ # rdoc-file=cont.c
374
+ # - fiber.kill -> nil
375
+ # -->
376
+ # Terminates the fiber by raising an uncatchable exception. It only terminates
377
+ # the given fiber and no other fiber, returning `nil` to another fiber if that
378
+ # fiber was calling #resume or #transfer.
379
+ #
380
+ # `Fiber#kill` only interrupts another fiber when it is in Fiber.yield. If
381
+ # called on the current fiber then it raises that exception at the `Fiber#kill`
382
+ # call site.
383
+ #
384
+ # If the fiber has not been started, transition directly to the terminated
385
+ # state.
386
+ #
387
+ # If the fiber is already terminated, does nothing.
388
+ #
389
+ # Raises FiberError if called on a fiber belonging to another thread.
390
+ #
391
+ def kill: () -> nil
392
+
372
393
  # <!--
373
394
  # rdoc-file=cont.c
374
395
  # - fiber.raise -> obj
@@ -389,6 +410,8 @@ class Fiber < Object
389
410
  # parameter is an array of callback information. Exceptions are caught by the
390
411
  # `rescue` clause of `begin...end` blocks.
391
412
  #
413
+ # Raises `FiberError` if called on a Fiber belonging to another `Thread`.
414
+ #
392
415
  def raise: (?string msg) -> untyped
393
416
  | (_Exception, ?string msg, ?Array[string] backtrace) -> untyped
394
417