Skip to content

Commit e4a11f4

Browse files
committed
Updated most of Kernel module methods
1 parent e72e205 commit e4a11f4

File tree

8 files changed

+1160
-121
lines changed

8 files changed

+1160
-121
lines changed

Diff for: core/builtin.rbs

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ interface _Range[T]
214214
def exclude_end?: () -> bool
215215
end
216216

217+
%a{steep:deprecate}
217218
interface _Exception
218219
def exception: () -> Exception
219220
| (String arg0) -> Exception

Diff for: core/exception.rbs

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@
106106
# * fatal
107107
#
108108
class Exception
109+
interface _Exception[T]
110+
def exception: (?T message) -> Exception
111+
end
112+
109113
# <!--
110114
# rdoc-file=error.c
111115
# - Exception.to_tty? -> true or false

Diff for: core/kernel.rbs

+72-51
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@
154154
# * #trap: Specifies the handling of system signals.
155155
# * #warn: Issue a warning based on the given messages and options.
156156
#
157-
%a{annotate:rdoc:source:from=object.c}
158157
module Kernel : BasicObject
159158
# <!--
160159
# rdoc-file=vm_backtrace.c
@@ -191,9 +190,9 @@ module Kernel : BasicObject
191190
# c(4) #=> []
192191
# c(5) #=> nil
193192
#
194-
def self?.caller: (Integer start_or_range, ?Integer length) -> ::Array[String]?
195-
| (::Range[Integer] start_or_range) -> ::Array[String]?
196-
| () -> ::Array[String]
193+
def self?.caller: () -> Array[String]
194+
| (int start, ?int? length) -> Array[String]?
195+
| (range[int?] range) -> Array[String]?
197196

198197
# <!--
199198
# rdoc-file=vm_backtrace.c
@@ -216,8 +215,9 @@ module Kernel : BasicObject
216215
# Optionally you can pass a range, which will return an array containing the
217216
# entries within the specified range.
218217
#
219-
def self?.caller_locations: (?Integer start_or_range, ?Integer length) -> ::Array[Thread::Backtrace::Location]?
220-
| (?::Range[Integer] start_or_range) -> ::Array[Thread::Backtrace::Location]?
218+
def self?.caller_locations: () -> Array[Thread::Backtrace::Location]
219+
| (int start, ?int? length) -> Array[Thread::Backtrace::Location]?
220+
| (range[int?] range) -> Array[Thread::Backtrace::Location]?
221221

222222
# <!--
223223
# rdoc-file=vm_eval.c
@@ -269,8 +269,8 @@ module Kernel : BasicObject
269269
#
270270
# # => 123
271271
#
272-
def self?.catch: [T] (T tag) { (T tag) -> untyped } -> untyped
273-
| () { (Object tag) -> untyped } -> untyped
272+
def self?.catch: () { (Object tag) -> untyped } -> untyped
273+
| [T] (T tag) { (T tag) -> untyped } -> untyped
274274

275275
# <!--
276276
# rdoc-file=kernel.rb
@@ -334,7 +334,7 @@ module Kernel : BasicObject
334334
# end
335335
# local_variables #=> [:fred, :i]
336336
#
337-
def self?.local_variables: () -> ::Array[Symbol]
337+
def self?.local_variables: () -> Array[Symbol]
338338

339339
# <!--
340340
# rdoc-file=random.c
@@ -441,7 +441,7 @@ module Kernel : BasicObject
441441
#
442442
def self?.Array: (nil) -> []
443443
| [T] (array[T] | _ToA[T] array_like) -> Array[T]
444-
| [T] (T ele) -> [T]
444+
| [T] (T element) -> [T]
445445

446446
# <!--
447447
# rdoc-file=complex.c
@@ -495,8 +495,8 @@ module Kernel : BasicObject
495495
#
496496
def self?.Complex: (_ToC complex_like, ?exception: true) -> Complex
497497
| (_ToC complex_like, exception: bool) -> Complex?
498-
| (Numeric | String real, ?Numeric | String imag, ?exception: true) -> Complex
499-
| (Numeric | String real, ?Numeric | String imag, exception: bool) -> Complex?
498+
| (Numeric | String real, ?(Numeric & _ToF) | String imag, ?exception: true) -> Complex
499+
| (Numeric | String real, ?(Numeric & _ToF) | String imag, exception: bool) -> Complex?
500500
| (untyped, ?untyped, ?exception: bool) -> Complex?
501501

502502
# <!--
@@ -541,7 +541,7 @@ module Kernel : BasicObject
541541
# Hash(nil) # => {}
542542
# Hash([]) # => {}
543543
#
544-
def self?.Hash: [K, V] (nil | [] _empty) -> Hash[K, V]
544+
def self?.Hash: [K, V] ([]?) -> Hash[K, V]
545545
| [K, V] (hash[K, V] hash_like) -> Hash[K, V]
546546

547547
# <!--
@@ -678,6 +678,7 @@ module Kernel : BasicObject
678678
| [T] (Numeric&_RationalDiv[T] numer, Numeric denom, ?exception: bool) -> T
679679
| [T < Numeric] (T value, 1, ?exception: bool) -> T
680680
| (untyped, ?untyped, ?exception: bool) -> Rational?
681+
| (__todo__) -> __todo__
681682

682683
interface _RationalDiv[T]
683684
def /: (Numeric) -> T
@@ -747,7 +748,7 @@ module Kernel : BasicObject
747748
#
748749
# The built-in syntax `%x{...}` uses this method.
749750
#
750-
def self?.`: (String arg0) -> String
751+
def self?.`: (string command) -> String
751752

752753
# <!--
753754
# rdoc-file=process.c
@@ -796,7 +797,7 @@ module Kernel : BasicObject
796797
# If *const* is defined as autoload, the file name to be loaded is replaced with
797798
# *filename*. If *const* is defined but not as autoload, does nothing.
798799
#
799-
def self?.autoload: (interned _module, String filename) -> NilClass
800+
def self?.autoload: (interned const, path filename) -> nil
800801

801802
# <!--
802803
# rdoc-file=load.c
@@ -807,7 +808,7 @@ module Kernel : BasicObject
807808
# autoload(:B, "b")
808809
# autoload?(:B) #=> "b"
809810
#
810-
def self?.autoload?: (interned name) -> String?
811+
def self?.autoload?: (interned name, ?boolish inherit) -> String?
811812

812813
# <!--
813814
# rdoc-file=proc.c
@@ -931,8 +932,7 @@ module Kernel : BasicObject
931932
#
932933
def self?.fail: () -> bot
933934
| (string message, ?cause: Exception?) -> bot
934-
| (_Exception exception, ?_ToS? message, ?String | Array[String] | nil backtrace, ?cause: Exception?) -> bot
935-
| (_Exception exception, ?cause: Exception?, **untyped) -> bot
935+
| [T] (Exception::_Exception[T] exception, ?T message, ?Array[String] | String | Thread::Backtrace | nil backtrace, ?cause: Exception?) -> bot
936936

937937
# <!--
938938
# rdoc-file=eval.c
@@ -964,26 +964,28 @@ module Kernel : BasicObject
964964

965965
alias self.raise self.fail
966966

967-
# <!-- rdoc-file=object.c -->
967+
# <!--
968+
# rdoc-file=object.c
969+
# - sprintf(format_string *objects) -> string
970+
# -->
968971
# Returns the string resulting from formatting `objects` into `format_string`.
969972
#
970973
# For details on `format_string`, see [Format
971974
# Specifications](rdoc-ref:format_specifications.rdoc).
972975
#
973-
def self?.format: (String format, *untyped args) -> String
976+
def self?.sprintf: (string format, hash[Symbol, untyped] keywords) -> String
977+
| (string format, **untyped keywords) -> String
978+
| (string format, *untyped positional) -> String
974979

975-
# <!--
976-
# rdoc-file=object.c
977-
# - sprintf(format_string *objects) -> string
978-
# -->
980+
# <!-- rdoc-file=object.c -->
979981
# Returns the string resulting from formatting `objects` into `format_string`.
980982
#
981983
# For details on `format_string`, see [Format
982984
# Specifications](rdoc-ref:format_specifications.rdoc).
983985
#
984-
alias sprintf format
986+
alias format sprintf
985987

986-
alias self.sprintf self.format
988+
alias self.format self.sprintf
987989

988990
# <!--
989991
# rdoc-file=io.c
@@ -1015,7 +1017,8 @@ module Kernel : BasicObject
10151017
# The style of programming using `$_` as an implicit parameter is gradually
10161018
# losing favor in the Ruby community.
10171019
#
1018-
def self?.gets: (?String arg0, ?Integer arg1) -> String?
1020+
def self?.gets: (?string? separator, ?int limit, ?chomp: boolish) -> String?
1021+
| (int limit, ?chomp: boolish) -> String?
10191022

10201023
# <!--
10211024
# rdoc-file=eval.c
@@ -1027,7 +1030,7 @@ module Kernel : BasicObject
10271030
#
10281031
# global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
10291032
#
1030-
def self?.global_variables: () -> ::Array[Symbol]
1033+
def self?.global_variables: () -> Array[Symbol]
10311034

10321035
# <!--
10331036
# rdoc-file=load.c
@@ -1056,7 +1059,7 @@ module Kernel : BasicObject
10561059
# executed under the given module. In no circumstance will any local variables
10571060
# in the loaded file be propagated to the loading environment.
10581061
#
1059-
def self?.load: (String filename, ?Module | bool) -> bool
1062+
def self?.load: (path filename, ?Module | bool wrap) -> true
10601063

10611064
# <!--
10621065
# rdoc-file=kernel.rb
@@ -1087,8 +1090,8 @@ module Kernel : BasicObject
10871090
# puts enum.next
10881091
# } #=> :ok
10891092
#
1090-
def self?.loop: () { () -> void } -> bot
1091-
| () -> ::Enumerator[nil, bot]
1093+
def self?.loop: () -> Enumerator[nil, untyped]
1094+
| () { () -> void } -> untyped
10921095

10931096
# <!--
10941097
# rdoc-file=io.c
@@ -1165,7 +1168,7 @@ module Kernel : BasicObject
11651168
# gets # Sets $_ to the most recent user input.
11661169
# print # Prints $_.
11671170
#
1168-
def self?.print: (*_ToS args) -> nil
1171+
def self?.print: (*_ToS objects) -> nil
11691172

11701173
# <!--
11711174
# rdoc-file=io.c
@@ -1200,16 +1203,20 @@ module Kernel : BasicObject
12001203
# With no arguments, does nothing.
12011204
#
12021205
def self?.printf: () -> nil
1203-
| (String fmt, *untyped args) -> nil
1204-
| (_Writer io, string fmt, *untyped args) -> nil
1206+
| (String fmt, hash[Symbol, untyped] keywords) -> nil
1207+
| (String fmt, **untyped keywords) -> nil
1208+
| (String fmt, *untyped positional) -> nil
1209+
| (_Writer io, string fmt, hash[Symbol, untyped] keywords) -> nil
1210+
| (_Writer io, string fmt, **untyped keywords) -> nil
1211+
| (_Writer io, string fmt, *untyped positional) -> nil
12051212

12061213
# <!--
12071214
# rdoc-file=proc.c
12081215
# - proc { |...| block } -> a_proc
12091216
# -->
12101217
# Equivalent to Proc.new.
12111218
#
1212-
def self?.proc: () { () -> untyped } -> Proc
1219+
def self?.proc: () { (?) -> untyped } -> Proc
12131220

12141221
# <!--
12151222
# rdoc-file=proc.c
@@ -1218,7 +1225,7 @@ module Kernel : BasicObject
12181225
# Equivalent to Proc.new, except the resulting Proc objects check the number of
12191226
# parameters passed when called.
12201227
#
1221-
def self?.lambda: () { () -> untyped } -> Proc
1228+
def self?.lambda: () { (?) -> untyped } -> Proc
12221229

12231230
# <!--
12241231
# rdoc-file=io.c
@@ -1230,8 +1237,8 @@ module Kernel : BasicObject
12301237
#
12311238
# See IO#putc for important information regarding multi-byte characters.
12321239
#
1233-
def self?.putc: [T < _ToInt] (T chr) -> T
1234-
| (String chr) -> String
1240+
def self?.putc: (String chr) -> String
1241+
| [T < _ToInt] (T chr) -> T
12351242

12361243
# <!--
12371244
# rdoc-file=io.c
@@ -1272,9 +1279,9 @@ module Kernel : BasicObject
12721279
# Kernel#p to be uninterruptible in whole or in part. On CRuby, Kernel#p's
12731280
# writing of data is uninterruptible.
12741281
#
1275-
def self?.p: [T < _Inspect] (T arg0) -> T
1276-
| (_Inspect arg0, _Inspect arg1, *_Inspect rest) -> Array[_Inspect]
1277-
| () -> nil
1282+
def self?.p: () -> nil
1283+
| [T < _Inspect] (T object) -> T
1284+
| [T < _Inspect] (T object1, T object2, *T objects) -> Array[T]
12781285

12791286
# <!--
12801287
# rdoc-file=lib/pp.rb
@@ -1284,9 +1291,9 @@ module Kernel : BasicObject
12841291
#
12851292
# pp returns argument(s).
12861293
#
1287-
def self?.pp: [T] (T arg0) -> T
1288-
| (untyped, untyped, *untyped) -> Array[untyped]
1289-
| () -> nil
1294+
def self?.pp: () -> nil
1295+
| [T < PP::_PrettyPrint] (T object) -> T
1296+
| [T < PP::_PrettyPrint] (T object1, T object2, *T objects) -> Array[T]
12901297

12911298
# <!--
12921299
# rdoc-file=random.c
@@ -1339,7 +1346,8 @@ module Kernel : BasicObject
13391346
# Optional keyword argument `chomp` specifies whether line separators are to be
13401347
# omitted.
13411348
#
1342-
def self?.readline: (?String arg0, ?Integer arg1) -> String
1349+
def self?.readline: (?string? separator, ?int limit, ?chomp: boolish) -> String
1350+
| (int limit, ?chomp: boolish) -> String
13431351

13441352
# <!--
13451353
# rdoc-file=io.c
@@ -1394,7 +1402,8 @@ module Kernel : BasicObject
13941402
# Optional keyword arguments `enc_opts` specify encoding options; see [Encoding
13951403
# options](rdoc-ref:encodings.rdoc@Encoding+Options).
13961404
#
1397-
def self?.readlines: (?String arg0, ?Integer arg1) -> ::Array[String]
1405+
def self?.readlines: (?string? separator, ?int limit, ?chomp: boolish) -> Array[String]
1406+
| (int limit, ?chomp: boolish) -> Array[String]
13981407

13991408
# <!--
14001409
# rdoc-file=lib/rubygems/core_ext/kernel_require.rb
@@ -1412,7 +1421,7 @@ module Kernel : BasicObject
14121421
# The normal `require` functionality of returning false if that file has already
14131422
# been loaded is preserved.
14141423
#
1415-
def self?.require: (String path) -> bool
1424+
def self?.require: (path feature) -> bool
14161425

14171426
# <!--
14181427
# rdoc-file=load.c
@@ -1423,7 +1432,7 @@ module Kernel : BasicObject
14231432
# raised. Returns `true` if the file was loaded and `false` if the file was
14241433
# already loaded before.
14251434
#
1426-
def self?.require_relative: (String feature) -> bool
1435+
def self?.require_relative: (path feature) -> bool
14271436

14281437
# <!--
14291438
# rdoc-file=io.c
@@ -1564,7 +1573,14 @@ module Kernel : BasicObject
15641573
# (snipped)
15651574
# ping
15661575
#
1567-
def self?.select: (::Array[IO] read, ?::Array[IO] write, ?::Array[IO] error, ?Time::_Timeout timeout) -> ::Array[String]
1576+
def self?.select: ([]?, ?[]?, ?[]?, ?nil) -> bot
1577+
| [R < _ToIO] (Array[R] read, ?[]?, ?[]?, ?nil ) -> [Array[R], [], []]
1578+
| [R < _ToIO] (Array[R] read, []?, []?, Time::_Timeout timeout) -> [Array[R], [], []]?
1579+
| [R < _ToIO, W < _ToIO] (Array[R] read, ?Array[W] write, ?[]?, ?nil ) -> [Array[R], Array[W], []]
1580+
| [R < _ToIO, W < _ToIO] (Array[R] read, Array[W] write, []?, Time::_Timeout timeout) -> [Array[R], Array[W], []]?
1581+
| [R < _ToIO, W < _ToIO, E < _ToIO] (Array[R] read, ?Array[W] write, ?Array[E] error, ?nil ) -> [Array[R], Array[W], Array[E]]
1582+
| [R < _ToIO, W < _ToIO, E < _ToIO] (Array[R] read, Array[W] write, Array[E] error, Time::_Timeout timeout) -> [Array[R], Array[W], Array[E]]?
1583+
| (Array[_ToIO]? read, ?Array[_ToIO]? write, ?Array[_ToIO]? error, ?Time::_Timeout? timeout) -> [Array[_ToIO], Array[_ToIO], Array[_ToIO]]?
15681584

15691585
# <!--
15701586
# rdoc-file=process.c
@@ -1670,7 +1686,12 @@ module Kernel : BasicObject
16701686
# ">" | boolean | True if the modification time of file1
16711687
# | | is after that of file2
16721688
#
1673-
def self?.test: (String | Integer cmd, String | IO file1, ?String | IO file2) -> (TrueClass | FalseClass | Time | nil | Integer)
1689+
def self?.test: ('b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'G' | 'k' | 'o' | 'O' | 'p' | 'S' | 'u' | 'z' | 98 | 99 | 100 | 101 | 102 | 103 | 71 | 107 | 111 | 79 | 112 | 83 | 117 | 122, IO | path file) -> bool
1690+
| ('l' | 'r' | 'R' | 'w' | 'W' | 'x' | 'X' | 108 | 114 | 82 | 119 | 87 | 120 | 88, path filename) -> bool
1691+
| ('s' | 115, IO | path filename) -> Integer?
1692+
| ('M' | 'A' | 'C' | 77 | 65 | 67, IO | path file) -> Time
1693+
| ('-' | '=' | '<' | '>' | 45 | 60 | 61 | 62, IO | path file1, IO | path file2) -> bool
1694+
| (String | int cmd, IO | path file1, ?IO | path file2) -> (bool | Integer? | Time)
16741695

16751696
# <!--
16761697
# rdoc-file=vm_eval.c
@@ -1728,7 +1749,7 @@ module Kernel : BasicObject
17281749
# :experimental
17291750
# : Used for experimental features that may change in future releases.
17301751
#
1731-
def self?.warn: (*_ToS msg, ?uplevel: int?, ?category: Warning::category?) -> nil
1752+
def self?.warn: (*_ToS msgs, ?uplevel: int?, ?category: Warning::category | _ToSym | nil) -> nil
17321753

17331754
# <!--
17341755
# rdoc-file=process.c

Diff for: lib/rbs/test/type_check.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def value(val, type)
331331
when Types::Variable
332332
true
333333
when Types::Literal
334-
type.literal == val
334+
defined?(val.==) and type.literal == val
335335
when Types::Union
336336
type.types.any? {|type| value(val, type) }
337337
when Types::Intersection

0 commit comments

Comments
 (0)