rbs 4.0.3 → 4.1.0.pre.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 (125) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/c-check.yml +3 -0
  3. data/.github/workflows/dependabot.yml +1 -1
  4. data/.github/workflows/jruby.yml +67 -0
  5. data/.github/workflows/milestone.yml +4 -1
  6. data/.github/workflows/ruby.yml +40 -0
  7. data/.github/workflows/rust.yml +3 -2
  8. data/.github/workflows/truffleruby.yml +54 -0
  9. data/.github/workflows/typecheck.yml +3 -0
  10. data/.github/workflows/wasm.yml +53 -0
  11. data/.github/workflows/windows.yml +3 -0
  12. data/.gitignore +7 -0
  13. data/CHANGELOG.md +0 -8
  14. data/README.md +3 -3
  15. data/Rakefile +118 -3
  16. data/Steepfile +7 -0
  17. data/config.yml +24 -0
  18. data/core/array.rbs +144 -144
  19. data/core/builtin.rbs +7 -6
  20. data/core/class.rbs +5 -3
  21. data/core/enumerable.rbs +109 -109
  22. data/core/enumerator/product.rbs +5 -5
  23. data/core/enumerator.rbs +28 -28
  24. data/core/file.rbs +24 -1018
  25. data/core/file_constants.rbs +463 -0
  26. data/core/file_stat.rbs +534 -0
  27. data/core/hash.rbs +117 -101
  28. data/core/integer.rbs +21 -58
  29. data/core/io.rbs +25 -7
  30. data/core/kernel.rbs +26 -11
  31. data/core/module.rbs +88 -74
  32. data/core/numeric.rbs +3 -0
  33. data/core/object_space/weak_key_map.rbs +7 -7
  34. data/core/range.rbs +23 -23
  35. data/core/rbs/ops.rbs +154 -0
  36. data/core/rbs/unnamed/argf.rbs +3 -3
  37. data/core/ruby_vm.rbs +40 -0
  38. data/core/set.rbs +3 -3
  39. data/core/struct.rbs +16 -16
  40. data/core/thread.rbs +6 -6
  41. data/docs/CONTRIBUTING.md +2 -1
  42. data/docs/inline.md +65 -7
  43. data/docs/rbs_by_example.md +20 -20
  44. data/docs/syntax.md +2 -2
  45. data/docs/wasm_serialization.md +80 -0
  46. data/ext/rbs_extension/ast_translation.c +1298 -956
  47. data/ext/rbs_extension/ast_translation.h +4 -0
  48. data/ext/rbs_extension/class_constants.c +2 -0
  49. data/ext/rbs_extension/class_constants.h +1 -0
  50. data/ext/rbs_extension/extconf.rb +1 -0
  51. data/ext/rbs_extension/main.c +139 -4
  52. data/include/rbs/ast.h +323 -298
  53. data/include/rbs/defines.h +13 -0
  54. data/include/rbs/lexer.h +1 -0
  55. data/include/rbs/serialize.h +39 -0
  56. data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
  57. data/lib/rbs/ast/ruby/annotations.rb +42 -0
  58. data/lib/rbs/ast/ruby/comment_block.rb +6 -4
  59. data/lib/rbs/ast/ruby/declarations.rb +11 -1
  60. data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
  61. data/lib/rbs/ast/ruby/members.rb +40 -1
  62. data/lib/rbs/buffer.rb +48 -11
  63. data/lib/rbs/cli.rb +3 -5
  64. data/lib/rbs/collection/config/lockfile_generator.rb +14 -1
  65. data/lib/rbs/collection/sources/git.rb +6 -0
  66. data/lib/rbs/definition_builder/method_builder.rb +12 -6
  67. data/lib/rbs/environment.rb +10 -3
  68. data/lib/rbs/inline_parser.rb +54 -28
  69. data/lib/rbs/namespace.rb +47 -11
  70. data/lib/rbs/prototype/runtime.rb +2 -0
  71. data/lib/rbs/resolver/type_name_resolver.rb +12 -14
  72. data/lib/rbs/rewriter.rb +70 -0
  73. data/lib/rbs/test/type_check.rb +6 -1
  74. data/lib/rbs/type_name.rb +33 -13
  75. data/lib/rbs/unit_test/type_assertions.rb +9 -0
  76. data/lib/rbs/version.rb +1 -1
  77. data/lib/rbs/wasm/deserializer.rb +213 -0
  78. data/lib/rbs/wasm/location.rb +61 -0
  79. data/lib/rbs/wasm/parser.rb +137 -0
  80. data/lib/rbs/wasm/runtime.rb +217 -0
  81. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  82. data/lib/rbs.rb +14 -2
  83. data/rbs.gemspec +19 -2
  84. data/sig/annotate/rdoc_annotater.rbs +12 -9
  85. data/sig/ast/ruby/annotations.rbs +49 -0
  86. data/sig/ast/ruby/members.rbs +21 -1
  87. data/sig/buffer.rbs +19 -1
  88. data/sig/collection/config/lockfile_generator.rbs +2 -0
  89. data/sig/inline_parser.rbs +2 -0
  90. data/sig/manifest.yaml +0 -1
  91. data/sig/namespace.rbs +20 -0
  92. data/sig/parser.rbs +10 -0
  93. data/sig/resolver/type_name_resolver.rbs +2 -4
  94. data/sig/rewriter.rbs +45 -0
  95. data/sig/typename.rbs +15 -0
  96. data/sig/unit_test/type_assertions.rbs +4 -0
  97. data/sig/wasm/deserializer.rbs +66 -0
  98. data/sig/wasm/serialization_schema.rbs +13 -0
  99. data/src/ast.c +186 -162
  100. data/src/lexer.c +137 -114
  101. data/src/lexer.re +1 -0
  102. data/src/lexstate.c +6 -1
  103. data/src/parser.c +55 -5
  104. data/src/serialize.c +958 -0
  105. data/src/util/rbs_allocator.c +1 -4
  106. data/stdlib/abbrev/0/array.rbs +1 -1
  107. data/stdlib/csv/0/csv.rbs +5 -5
  108. data/stdlib/digest/0/digest.rbs +1 -1
  109. data/stdlib/etc/0/etc.rbs +18 -4
  110. data/stdlib/fileutils/0/fileutils.rbs +21 -21
  111. data/stdlib/json/0/json.rbs +6 -6
  112. data/stdlib/openssl/0/openssl.rbs +7 -7
  113. data/stdlib/resolv/0/resolv.rbs +1 -1
  114. data/stdlib/shellwords/0/shellwords.rbs +1 -1
  115. data/stdlib/stringio/0/stringio.rbs +32 -10
  116. data/stdlib/strscan/0/string_scanner.rbs +74 -55
  117. data/stdlib/tsort/0/cyclic.rbs +1 -1
  118. data/stdlib/tsort/0/interfaces.rbs +8 -8
  119. data/stdlib/tsort/0/tsort.rbs +9 -9
  120. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  121. data/wasm/README.md +59 -0
  122. data/wasm/rbs_wasm.c +411 -0
  123. metadata +23 -5
  124. data/.vscode/extensions.json +0 -5
  125. data/.vscode/settings.json +0 -19
data/core/range.rbs CHANGED
@@ -235,8 +235,8 @@
235
235
  #
236
236
  # require 'json/add/range'
237
237
  #
238
- class Range[out Elem] < Object
239
- include Enumerable[Elem]
238
+ class Range[out E] < Object
239
+ include Enumerable[E]
240
240
 
241
241
  # <!--
242
242
  # rdoc-file=range.c
@@ -260,8 +260,8 @@ class Range[out Elem] < Object
260
260
  # (0..7) % 2 #=> ((0..7).%(2)) -- as expected
261
261
  # 0..7 % 2 #=> 0..1 -- parsed as 0..(7 % 2)
262
262
  #
263
- def %: (Numeric | int n) -> Enumerator[Elem, self]
264
- | (Numeric | int n) { (Elem element) -> void } -> self
263
+ def %: (Numeric | int n) -> Enumerator[E, self]
264
+ | (Numeric | int n) { (E element) -> void } -> self
265
265
 
266
266
  # <!--
267
267
  # rdoc-file=range.c
@@ -345,7 +345,7 @@ class Range[out Elem] < Object
345
345
  #
346
346
  # Related: Range#first, Range#end.
347
347
  #
348
- def begin: () -> Elem
348
+ def begin: () -> E
349
349
 
350
350
  # <!--
351
351
  # rdoc-file=range.c
@@ -355,9 +355,9 @@ class Range[out Elem] < Object
355
355
  #
356
356
  # See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
357
357
  #
358
- def bsearch: () -> ::Enumerator[Elem, Elem?]
359
- | () { (Elem) -> (true | false) } -> Elem?
360
- | () { (Elem) -> ::Integer } -> Elem?
358
+ def bsearch: () -> ::Enumerator[E, E?]
359
+ | () { (E) -> (true | false) } -> E?
360
+ | () { (E) -> ::Integer } -> E?
361
361
 
362
362
  # <!--
363
363
  # rdoc-file=range.c
@@ -500,8 +500,8 @@ class Range[out Elem] < Object
500
500
  #
501
501
  # With no block given, returns an enumerator.
502
502
  #
503
- def each: () { (Elem arg0) -> untyped } -> self
504
- | () -> ::Enumerator[Elem, self]
503
+ def each: () { (E arg0) -> untyped } -> self
504
+ | () -> ::Enumerator[E, self]
505
505
 
506
506
  # <!--
507
507
  # rdoc-file=range.c
@@ -515,7 +515,7 @@ class Range[out Elem] < Object
515
515
  #
516
516
  # Related: Range#begin, Range#last.
517
517
  #
518
- def end: () -> Elem
518
+ def end: () -> E
519
519
 
520
520
  # <!--
521
521
  # rdoc-file=range.c
@@ -551,8 +551,8 @@ class Range[out Elem] < Object
551
551
  #
552
552
  # (..4).first # Raises RangeError
553
553
  #
554
- def first: () -> Elem
555
- | (Integer n) -> ::Array[Elem]
554
+ def first: () -> E
555
+ | (Integer n) -> ::Array[E]
556
556
 
557
557
  # <!--
558
558
  # rdoc-file=range.c
@@ -605,7 +605,7 @@ class Range[out Elem] < Object
605
605
  # Range.new('a', 'd').to_a # => ["a", "b", "c", "d"]
606
606
  # Range.new('a', 'd', true).to_a # => ["a", "b", "c"]
607
607
  #
608
- def initialize: (Elem from, Elem to, ?boolish exclude_end) -> void
608
+ def initialize: (E from, E to, ?boolish exclude_end) -> void
609
609
 
610
610
  # <!--
611
611
  # rdoc-file=range.c
@@ -661,8 +661,8 @@ class Range[out Elem] < Object
661
661
  #
662
662
  # (1..).last # Raises RangeError
663
663
  #
664
- def last: () -> Elem
665
- | (Integer n) -> ::Array[Elem]
664
+ def last: () -> E
665
+ | (Integer n) -> ::Array[E]
666
666
 
667
667
  # <!--
668
668
  # rdoc-file=range.c
@@ -958,8 +958,8 @@ class Range[out Elem] < Object
958
958
  #
959
959
  # With no block given, returns an enumerator.
960
960
  #
961
- def reverse_each: () { (Elem) -> void } -> self
962
- | () -> ::Enumerator[Elem, self]
961
+ def reverse_each: () { (E) -> void } -> self
962
+ | () -> ::Enumerator[E, self]
963
963
 
964
964
  # <!--
965
965
  # rdoc-file=range.c
@@ -1016,7 +1016,7 @@ class Range[out Elem] < Object
1016
1016
  #
1017
1017
  def count: () -> (Integer | Float)
1018
1018
  | (untyped) -> Integer
1019
- | () { (Elem) -> boolish } -> Integer
1019
+ | () { (E) -> boolish } -> Integer
1020
1020
 
1021
1021
  # <!--
1022
1022
  # rdoc-file=range.c
@@ -1096,10 +1096,10 @@ class Range[out Elem] < Object
1096
1096
  # ('a'..'e').step { p _1 }
1097
1097
  # # Default step 1; prints: a, b, c, d, e
1098
1098
  #
1099
- def step: (?Numeric | int) -> Enumerator[Elem, self]
1100
- | (?Numeric | int) { (Elem element) -> void } -> self
1101
- | (untyped) -> Enumerator[Elem, self]
1102
- | (untyped) { (Elem element) -> void } -> self
1099
+ def step: (?Numeric | int) -> Enumerator[E, self]
1100
+ | (?Numeric | int) { (E element) -> void } -> self
1101
+ | (untyped) -> Enumerator[E, self]
1102
+ | (untyped) { (E element) -> void } -> self
1103
1103
 
1104
1104
  # <!--
1105
1105
  # rdoc-file=range.c
data/core/rbs/ops.rbs ADDED
@@ -0,0 +1,154 @@
1
+ module RBS
2
+ module Ops
3
+ # An interface for types implementing the `+` operator
4
+ interface _Add[O, R]
5
+ # Perform the `+` operation
6
+ def +: (O other) -> R
7
+ end
8
+
9
+ # An interface for types implementing the `-` operator
10
+ interface _Subtract[O, R]
11
+ # Perform the `-` operation
12
+ def -: (O other) -> R
13
+ end
14
+
15
+ # An interface for types implementing the `*` operator
16
+ interface _Times[O, R]
17
+ # Perform the `*` operation
18
+ def *: (O other) -> R
19
+ end
20
+
21
+ # An interface for types implementing the `/` operator
22
+ interface _Divide[O, R]
23
+ # Perform the `/` operation
24
+ def /: (O other) -> R
25
+ end
26
+
27
+ # An interface for types implementing the `%` operator
28
+ interface _Modulo[O, R]
29
+ # Perform the `%` operation
30
+ def %: (O other) -> R
31
+ end
32
+
33
+ # An interface for types implementing the `**` operator
34
+ interface _Power[O, R]
35
+ # Perform the `**` operation
36
+ def **: (O other) -> R
37
+ end
38
+
39
+ # An interface for types implementing the `<` operator
40
+ interface _LessThan[O, R = bool]
41
+ # Perform the `<` operation
42
+ def <: (O other) -> R
43
+ end
44
+
45
+ # An interface for types implementing the `>` operator
46
+ interface _GreaterThan[O, R = bool]
47
+ # Perform the `>` operation
48
+ def >: (O other) -> R
49
+ end
50
+
51
+ # An interface for types implementing the `<=` operator
52
+ interface _LessThanOrEqual[O, R = bool]
53
+ # Perform the `<=` operation
54
+ def <=: (O other) -> R
55
+ end
56
+
57
+ # An interface for types implementing the `>=` operator
58
+ interface _GreaterThanOrEqual[O, R = bool]
59
+ # Perform the `>=` operation
60
+ def >=: (O other) -> R
61
+ end
62
+
63
+ # An interface for types implementing the `<=>` operator
64
+ interface _Compare[O = untyped, R = (-1 | 0 | 1)?]
65
+ # Perform the `<=>` operation
66
+ def <=>: (O other) -> R
67
+ end
68
+
69
+ # An interface for types implementing the `&` operator
70
+ interface _And[O, R]
71
+ # Perform the `&` operation
72
+ def &: (O other) -> R
73
+ end
74
+
75
+ # An interface for types implementing the `|` operator
76
+ interface _Or[O, R]
77
+ # Perform the `|` operation
78
+ def |: (O other) -> R
79
+ end
80
+
81
+ # An interface for types implementing the `^` operator
82
+ interface _Xor[O, R]
83
+ # Perform the `^` operation
84
+ def ^: (O other) -> R
85
+ end
86
+
87
+ # An interface for types implementing the `<<` operator
88
+ interface _LeftShift[O, R]
89
+ # Perform the `<<` operation
90
+ def <<: (O other) -> R
91
+ end
92
+
93
+ # An interface for types implementing the `>>` operator
94
+ interface _RightShift[O, R]
95
+ # Perform the `>>` operation
96
+ def >>: (O other) -> R
97
+ end
98
+
99
+ # An interface for types implementing the `~` operator
100
+ interface _Not[R]
101
+ # Perform the `~` operation
102
+ def ~: () -> R
103
+ end
104
+
105
+ # An interface for types implementing the `+@` operator
106
+ interface _UnaryPos[R]
107
+ # Perform the `+@` operation
108
+ def +@: () -> R
109
+ end
110
+
111
+ # An interface for types implementing the `-@` operator
112
+ interface _UnaryNeg[R]
113
+ # Perform the `-@` operation
114
+ def -@: () -> R
115
+ end
116
+
117
+ # An interface for types implementing the `!` operator
118
+ interface _LogicalNot[R = bool]
119
+ # Perform the `!` operation
120
+ def !: () -> R
121
+ end
122
+
123
+ # An interface for types implementing the `==` operator
124
+ interface _Equal[O = untyped, R = bool]
125
+ # Perform the `==` operation
126
+ def ==: (O other) -> R
127
+ end
128
+
129
+ # An interface for types implementing the `===` operator
130
+ interface _CaseEqual[O, R = bool]
131
+ # Perform the `===` operation
132
+ def ===: (O other) -> R
133
+ end
134
+
135
+ # An interface for types implementing the `=~` operator
136
+ interface _Matches[O, R]
137
+ # Perform the `=~` operation
138
+ def =~: (O other) -> R
139
+ end
140
+
141
+ # An interface for types implementing the `!=` operator
142
+ interface _NotEqual[O = untyped, R = bool]
143
+ # Perform the `!=` operation
144
+ def !=: (O other) -> R
145
+ end
146
+
147
+ # An interface for types implementing the `!~` operator
148
+ interface _NotMatches[O, R = bool]
149
+ # Perform the `!~` operation
150
+ def !~: (O other) -> R
151
+ end
152
+ end
153
+ end
154
+
@@ -959,7 +959,7 @@ module RBS
959
959
  # ARGF#readpartial or ARGF#read_nonblock.
960
960
  #
961
961
  %a{annotate:rdoc:copy:ARGF#read}
962
- def read: (?int? length, ?string outbuf) -> String?
962
+ def read: (?int? length, ?string? outbuf) -> String?
963
963
 
964
964
  # <!--
965
965
  # rdoc-file=io.c
@@ -969,7 +969,7 @@ module RBS
969
969
  # Reads at most *maxlen* bytes from the ARGF stream in non-blocking mode.
970
970
  #
971
971
  %a{annotate:rdoc:copy:ARGF#read_nonblock}
972
- def read_nonblock: (int maxlen, ?string buf, **untyped options) -> String
972
+ def read_nonblock: (int maxlen, ?string? buf, **untyped options) -> String
973
973
 
974
974
  # <!--
975
975
  # rdoc-file=io.c
@@ -1070,7 +1070,7 @@ module RBS
1070
1070
  # last one.
1071
1071
  #
1072
1072
  %a{annotate:rdoc:copy:ARGF#readpartial}
1073
- def readpartial: (int maxlen, ?string outbuf) -> String
1073
+ def readpartial: (int maxlen, ?string? outbuf) -> String
1074
1074
 
1075
1075
  # <!--
1076
1076
  # rdoc-file=io.c
data/core/ruby_vm.rbs CHANGED
@@ -371,6 +371,46 @@ class RubyVM::InstructionSequence < Object
371
371
  # event_symbol] pair.
372
372
  #
373
373
  def trace_points: () -> Array[untyped]
374
+
375
+ # <!--
376
+ # rdoc-file=iseq.c
377
+ # - of(p1)
378
+ # -->
379
+ # Returns the instruction sequence containing the given proc or method.
380
+ #
381
+ # For example, using irb:
382
+ #
383
+ # # a proc
384
+ # > p = proc { num = 1 + 2 }
385
+ # > RubyVM::InstructionSequence.of(p)
386
+ # > #=> <RubyVM::InstructionSequence:block in irb_binding@(irb)>
387
+ #
388
+ # # for a method
389
+ # > def foo(bar); puts bar; end
390
+ # > RubyVM::InstructionSequence.of(method(:foo))
391
+ # > #=> <RubyVM::InstructionSequence:foo@(irb)>
392
+ #
393
+ # Using ::compile_file:
394
+ #
395
+ # # /tmp/iseq_of.rb
396
+ # def hello
397
+ # puts "hello, world"
398
+ # end
399
+ #
400
+ # $a_global_proc = proc { str = 'a' + 'b' }
401
+ #
402
+ # # in irb
403
+ # > require '/tmp/iseq_of.rb'
404
+ #
405
+ # # first the method hello
406
+ # > RubyVM::InstructionSequence.of(method(:hello))
407
+ # > #=> #<RubyVM::InstructionSequence:0x007fb73d7cb1d0>
408
+ #
409
+ # # then the global proc
410
+ # > RubyVM::InstructionSequence.of($a_global_proc)
411
+ # > #=> #<RubyVM::InstructionSequence:0x007fb73d7caf78>
412
+ #
413
+ def self.of: (Proc | Method | UnboundMethod body) -> RubyVM::InstructionSequence?
374
414
  end
375
415
 
376
416
  # <!-- rdoc-file=ast.rb -->
data/core/set.rbs CHANGED
@@ -738,7 +738,7 @@ class Set[unchecked out A]
738
738
  end
739
739
 
740
740
  %a{annotate:rdoc:skip}
741
- module Enumerable[unchecked out Elem]
741
+ module Enumerable[unchecked out E]
742
742
  # <!--
743
743
  # rdoc-file=prelude.rb
744
744
  # - to_set(*args, &block)
@@ -746,6 +746,6 @@ module Enumerable[unchecked out Elem]
746
746
  # Makes a set from the enumerable object with given arguments. Passing arguments
747
747
  # to this method is deprecated.
748
748
  #
749
- def to_set: () -> Set[Elem]
750
- | [T] () { (Elem) -> T } -> Set[T]
749
+ def to_set: () -> Set[E]
750
+ | [T] () { (E) -> T } -> Set[T]
751
751
  end
data/core/struct.rbs CHANGED
@@ -104,8 +104,8 @@
104
104
  # * #inspect (aliased as #to_s): Returns a string representation of `self`.
105
105
  # * #to_h: Returns a hash of the member name/value pairs in `self`.
106
106
  #
107
- class Struct[Elem]
108
- include Enumerable[Elem]
107
+ class Struct[E]
108
+ include Enumerable[E]
109
109
 
110
110
  # The types that can be used when "indexing" into a `Struct` via `[]`, `[]=`, `dig`, and
111
111
  # `deconstruct_keys`.
@@ -362,7 +362,7 @@ class Struct[Elem]
362
362
  #
363
363
  # Related: #members.
364
364
  #
365
- def to_a: () -> Array[Elem]
365
+ def to_a: () -> Array[E]
366
366
 
367
367
  # <!--
368
368
  # rdoc-file=struct.c
@@ -385,8 +385,8 @@ class Struct[Elem]
385
385
  #
386
386
  # Raises ArgumentError if the block returns an inappropriate value.
387
387
  #
388
- def to_h: () -> Hash[Symbol, Elem]
389
- | [K, V] () { (Symbol key, Elem value) -> [K, V] } -> Hash[K, V]
388
+ def to_h: () -> Hash[Symbol, E]
389
+ | [K, V] () { (Symbol key, E value) -> [K, V] } -> Hash[K, V]
390
390
 
391
391
  # <!-- rdoc-file=struct.c -->
392
392
  # Returns the values in `self` as an array:
@@ -441,8 +441,8 @@ class Struct[Elem]
441
441
  #
442
442
  # Related: #each_pair.
443
443
  #
444
- def each: () -> Enumerator[Elem, self]
445
- | () { (Elem value) -> void } -> self
444
+ def each: () -> Enumerator[E, self]
445
+ | () { (E value) -> void } -> self
446
446
 
447
447
  # <!--
448
448
  # rdoc-file=struct.c
@@ -465,8 +465,8 @@ class Struct[Elem]
465
465
  #
466
466
  # Related: #each.
467
467
  #
468
- def each_pair: () -> Enumerator[[Symbol, Elem], self]
469
- | () { ([Symbol, Elem] key_value) -> void } -> self
468
+ def each_pair: () -> Enumerator[[Symbol, E], self]
469
+ | () { ([Symbol, E] key_value) -> void } -> self
470
470
 
471
471
  # <!--
472
472
  # rdoc-file=struct.c
@@ -492,7 +492,7 @@ class Struct[Elem]
492
492
  #
493
493
  # Raises IndexError if `n` is out of range.
494
494
  #
495
- def []: (index name_or_position) -> Elem
495
+ def []: (index name_or_position) -> E
496
496
 
497
497
  # <!--
498
498
  # rdoc-file=struct.c
@@ -521,7 +521,7 @@ class Struct[Elem]
521
521
  #
522
522
  # Raises IndexError if `n` is out of range.
523
523
  #
524
- def []=: (index name_or_position, Elem value) -> Elem
524
+ def []=: (index name_or_position, E value) -> E
525
525
 
526
526
  # <!--
527
527
  # rdoc-file=struct.c
@@ -540,8 +540,8 @@ class Struct[Elem]
540
540
  #
541
541
  # With no block given, returns an Enumerator.
542
542
  #
543
- def select: () -> Enumerator[Elem, Array[Elem]]
544
- | () { (Elem value) -> boolish } -> Array[Elem]
543
+ def select: () -> Enumerator[E, Array[E]]
544
+ | () { (E value) -> boolish } -> Array[E]
545
545
 
546
546
  # <!-- rdoc-file=struct.c -->
547
547
  # With a block given, returns an array of values from `self` for which the block
@@ -591,7 +591,7 @@ class Struct[Elem]
591
591
  # Raises RangeError if any element of the range is negative and out of range;
592
592
  # see Array@Array+Indexes.
593
593
  #
594
- def values_at: (*int | range[int?] positions) -> Array[Elem]
594
+ def values_at: (*int | range[int?] positions) -> Array[E]
595
595
 
596
596
  # <!--
597
597
  # rdoc-file=struct.c
@@ -634,7 +634,7 @@ class Struct[Elem]
634
634
  # f.dig(0, 0, :b, 0) # => 1
635
635
  # f.dig(:b, 0) # => nil
636
636
  #
637
- def dig: (index name_or_position) -> Elem
637
+ def dig: (index name_or_position) -> E
638
638
  | (index name_or_position, untyped, *untyped) -> untyped
639
639
 
640
640
  # <!-- rdoc-file=struct.c -->
@@ -664,5 +664,5 @@ class Struct[Elem]
664
664
  # h = joe.deconstruct_keys(nil)
665
665
  # h # => {:name=>"Joseph Smith, Jr.", :address=>"123 Maple, Anytown NC", :zip=>12345}
666
666
  #
667
- def deconstruct_keys: (Array[index & Hash::_Key]? indices) -> Hash[index & Hash::_Key, Elem]
667
+ def deconstruct_keys: (Array[index & Hash::_Key]? indices) -> Hash[index & Hash::_Key, E]
668
668
  end
data/core/thread.rbs CHANGED
@@ -1604,7 +1604,7 @@ end
1604
1604
  #
1605
1605
  # consumer.join
1606
1606
  #
1607
- class Thread::Queue[Elem = untyped] < Object
1607
+ class Thread::Queue[E = untyped] < Object
1608
1608
  # <!-- rdoc-file=thread_sync.c -->
1609
1609
  # Pushes the given `object` to the queue.
1610
1610
  #
@@ -1719,7 +1719,7 @@ class Thread::Queue[Elem = untyped] < Object
1719
1719
  # If `timeout` seconds have passed and no data is available `nil` is returned.
1720
1720
  # If `timeout` is `0` it returns immediately.
1721
1721
  #
1722
- def pop: (?boolish non_block, ?timeout: _ToF?) -> Elem?
1722
+ def pop: (?boolish non_block, ?timeout: _ToF?) -> E?
1723
1723
 
1724
1724
  # <!--
1725
1725
  # rdoc-file=thread_sync.c
@@ -1729,7 +1729,7 @@ class Thread::Queue[Elem = untyped] < Object
1729
1729
  # -->
1730
1730
  # Pushes the given `object` to the queue.
1731
1731
  #
1732
- def push: (Elem obj) -> void
1732
+ def push: (E obj) -> void
1733
1733
 
1734
1734
  # <!--
1735
1735
  # rdoc-file=thread_sync.rb
@@ -1750,7 +1750,7 @@ end
1750
1750
  #
1751
1751
  # See Thread::Queue for an example of how a Thread::SizedQueue works.
1752
1752
  #
1753
- class Thread::SizedQueue[Elem = untyped] < Thread::Queue[Elem]
1753
+ class Thread::SizedQueue[E = untyped] < Thread::Queue[E]
1754
1754
  # <!--
1755
1755
  # rdoc-file=thread_sync.rb
1756
1756
  # - <<(object, non_block = false, timeout: nil)
@@ -1813,8 +1813,8 @@ class Thread::SizedQueue[Elem = untyped] < Thread::Queue[Elem]
1813
1813
  # If `timeout` seconds have passed and no space is available `nil` is returned.
1814
1814
  # If `timeout` is `0` it returns immediately. Otherwise it returns `self`.
1815
1815
  #
1816
- def push: (Elem obj, ?boolish non_block) -> void
1817
- | (Elem obj, timeout: _ToF?) -> self?
1816
+ def push: (E obj, ?boolish non_block) -> void
1817
+ | (E obj, timeout: _ToF?) -> self?
1818
1818
  end
1819
1819
 
1820
1820
  class ConditionVariable = Thread::ConditionVariable
data/docs/CONTRIBUTING.md CHANGED
@@ -12,7 +12,8 @@
12
12
  The RBS repository contains the type definitions of Core API and Standard Libraries.
13
13
  There are some discussions whether if it is the best to have them in this repository, but we have them and continue updating the files meanwhile.
14
14
 
15
- The target version of the bundled type definitions is the latest _release_ of Ruby -- `3.1` as of January 2022.
15
+ The target version of the bundled type definitions is the [latest _release_ of Ruby](https://www.ruby-lang.org/en/downloads/branches/) -- `4.0` as of 2026.
16
+ Note, however, that the CI currently retains the tests on Ruby 3.2 as well.
16
17
 
17
18
  **The core API** type definitions are in `core` directory.
18
19
  You will find the familiar class names in the directory, like `string.rbs` or `array.rbs`.
data/docs/inline.md CHANGED
@@ -123,10 +123,38 @@ end
123
123
 
124
124
  This creates the types `::API`, `::API::V1`, and `::API::V1::Resources`.
125
125
 
126
+ ### `module-self` constraint
127
+
128
+ The `module-self` constraint declares which classes or modules the module can be mixed into.
129
+
130
+ ```ruby
131
+ # @rbs module-self: _Each[String]
132
+ module Enumerable2
133
+ end
134
+ ```
135
+
136
+ This is equivalent to `module Enumerable2 : _Each[String]` in RBS, meaning `Enumerable2` can only be included in classes that satisfy the `_Each[String]` interface.
137
+
138
+ Multiple `module-self` constraints can be declared with separate annotations:
139
+
140
+ ```ruby
141
+ # @rbs module-self: _Each[String]
142
+ # @rbs module-self: Comparable
143
+ module StringCollection
144
+ end
145
+ ```
146
+
147
+ You can add a description after `--`:
148
+
149
+ ```ruby
150
+ # @rbs module-self: Minitest::Test -- depending on assertion methods
151
+ module TestHelper
152
+ end
153
+ ```
154
+
126
155
  ### Current Limitations
127
156
 
128
157
  - Generic module definitions are not supported
129
- - Module self-type constraints are not supported
130
158
 
131
159
  ## Method Definitions
132
160
 
@@ -135,6 +163,8 @@ Inline RBS supports methods defined using the `def` syntax in Ruby.
135
163
  ```ruby
136
164
  class Calculator
137
165
  def add(x, y) = x+y
166
+
167
+ def self.zero = 0
138
168
  end
139
169
  ```
140
170
 
@@ -205,6 +235,18 @@ The type of both methods is `(Integer, Integer) -> Integer | (Float, Float) -> F
205
235
  > The `@rbs METHOD-TYPE` syntax allows overloads with the `|` operator, just like in RBS files.
206
236
  > Multiple `: METHOD-TYPE` declarations are required for overloads.
207
237
 
238
+ The `#:` syntax can also be used as a trailing annotation to declare the return type of a method:
239
+
240
+ ```ruby
241
+ class Calculator
242
+ def add(x, y) #: Integer
243
+ x + y
244
+ end
245
+
246
+ def subtract(x, y) = x - y #: Integer
247
+ end
248
+ ```
249
+
208
250
  The `@rbs METHOD-TYPE` syntax allows having `...` at the last part.
209
251
 
210
252
  ```ruby
@@ -309,9 +351,10 @@ end
309
351
 
310
352
  ### Current Limitations
311
353
 
312
- - Class methods and singleton methods are not supported
313
- - Only positional and keyword parameters are supported. Splat parameters (`*x`, `**y`) and block parameter (`&block`) are not supported yet.
314
354
  - Method visibility declaration is not supported yet
355
+ - The `class << self` syntax is not supported
356
+ - Top-level method definitions (outside any class/module) are not supported
357
+ - Method definitions with a non-self receiver (e.g. `def obj.foo`) are not supported
315
358
 
316
359
  ## Attributes
317
360
 
@@ -389,6 +432,7 @@ The attribute definitions are ignored because the names are given by string lite
389
432
  ### Current Limitations
390
433
 
391
434
  - Attribute visibility is not supported yet. All attributes are _public_
435
+ - Top-level attribute definitions (outside any class/module) are not supported
392
436
 
393
437
  ## Mixin
394
438
 
@@ -487,7 +531,7 @@ end
487
531
  ```
488
532
 
489
533
  The `@rbs @VAR-NAME: TYPE` syntax enclosed in `class`/`module` syntax declares instance variables.
490
- You can add the documentation of the variable followed by two hyphones (`--`).
534
+ You can add the documentation of the variable followed by two hyphens (`--`).
491
535
 
492
536
  Instance variable declarations must be under the `class`/`module` syntax, and they are ignored if written inside method definitions.
493
537
 
@@ -519,14 +563,16 @@ The types of constants may be automatically inferred when the right-hand side co
519
563
  - **Floats**: `RATE = 3.14` → `Float`
520
564
  - **Booleans**: `ENABLED = true` → `bool`
521
565
  - **Strings**: `NAME = "test"` → `String`
522
- - **Symbols**: `STATUS = :ready` → `:ready`
566
+ - **Symbols**: `STATUS = :ready` → `Symbol`
567
+ - **Nil**: `EMPTY = nil` → `nil`
523
568
 
524
569
  ```ruby
525
570
  MAX_SIZE = 100 # Inferred as Integer
526
571
  PI = 3.14159 # Inferred as Float
527
572
  DEBUG = false # Inferred as bool
528
573
  APP_NAME = "MyApp" # Inferred as String
529
- DEFAULT_MODE = :strict # Inferred as :strict
574
+ DEFAULT_MODE = :strict # Inferred as Symbol
575
+ NONE = nil # Inferred as nil
530
576
  ```
531
577
 
532
578
  ### Explicit Type Annotations
@@ -567,10 +613,22 @@ MyKernel = Kernel #: module-alias
567
613
 
568
614
  This creates new type names that refer to the same class or module as the original.
569
615
 
570
- The annotations can have optional type name to specify the class/module name, for the case it cannot be infered through the right-hand-side of the constant declaration.
616
+ The annotations can have optional type name to specify the class/module name, for the case it cannot be inferred through the right-hand-side of the constant declaration.
571
617
 
572
618
  ```ruby
573
619
  MyObject = object #: class-alias Object
574
620
 
575
621
  MyKernel = kernel #: module-alias Kernel
576
622
  ```
623
+
624
+ ## Skip Annotation
625
+
626
+ The `@rbs skip` annotation makes inline RBS ignore the following declaration.
627
+
628
+ ```ruby
629
+ class Calculator
630
+ # @rbs skip
631
+ def debug_internal
632
+ end
633
+ end
634
+ ```