Skip to content

Commit c695200

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

File tree

8 files changed

+1007
-395
lines changed

8 files changed

+1007
-395
lines changed

core/builtin.rbs

Lines changed: 1 addition & 0 deletions
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

core/exception.rbs

Lines changed: 4 additions & 0 deletions
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

core/kernel.rbs

Lines changed: 67 additions & 47 deletions
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
@@ -699,7 +700,6 @@ module Kernel : BasicObject
699700
#
700701
def self?.String: (string | _ToS string_like) -> String
701702

702-
# <!--
703703
# rdoc-file=eval.c
704704
# - __callee__ -> symbol
705705
# -->
@@ -747,7 +747,7 @@ module Kernel : BasicObject
747747
#
748748
# The built-in syntax `%x{...}` uses this method.
749749
#
750-
def self?.`: (String arg0) -> String
750+
def self?.`: (string command) -> String
751751

752752
# <!--
753753
# rdoc-file=process.c
@@ -796,7 +796,7 @@ module Kernel : BasicObject
796796
# If *const* is defined as autoload, the file name to be loaded is replaced with
797797
# *filename*. If *const* is defined but not as autoload, does nothing.
798798
#
799-
def self?.autoload: (interned _module, String filename) -> NilClass
799+
def self?.autoload: (interned const, path filename) -> nil
800800

801801
# <!--
802802
# rdoc-file=load.c
@@ -807,7 +807,7 @@ module Kernel : BasicObject
807807
# autoload(:B, "b")
808808
# autoload?(:B) #=> "b"
809809
#
810-
def self?.autoload?: (interned name) -> String?
810+
def self?.autoload?: (interned name, ?boolish inherit) -> String?
811811

812812
# <!--
813813
# rdoc-file=proc.c
@@ -931,8 +931,7 @@ module Kernel : BasicObject
931931
#
932932
def self?.fail: () -> bot
933933
| (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
934+
| [T] (Exception::_Exception[T] exception, ?T message, ?Array[String] | String | Thread::Backtrace | nil backtrace, ?cause: Exception?) -> bot
936935

937936
# <!--
938937
# rdoc-file=eval.c
@@ -970,7 +969,9 @@ module Kernel : BasicObject
970969
# For details on `format_string`, see [Format
971970
# Specifications](rdoc-ref:format_specifications.rdoc).
972971
#
973-
def self?.format: (String format, *untyped args) -> String
972+
def self?.sprintf: (string format, hash[Symbol, untyped] keywords) -> String
973+
| (string format, **untyped keywords) -> String
974+
| (string format, *untyped positional) -> String
974975

975976
# <!--
976977
# rdoc-file=object.c
@@ -981,9 +982,9 @@ module Kernel : BasicObject
981982
# For details on `format_string`, see [Format
982983
# Specifications](rdoc-ref:format_specifications.rdoc).
983984
#
984-
alias sprintf format
985+
alias format sprintf
985986

986-
alias self.sprintf self.format
987+
alias self.format self.sprintf
987988

988989
# <!--
989990
# rdoc-file=io.c
@@ -1015,7 +1016,8 @@ module Kernel : BasicObject
10151016
# The style of programming using `$_` as an implicit parameter is gradually
10161017
# losing favor in the Ruby community.
10171018
#
1018-
def self?.gets: (?String arg0, ?Integer arg1) -> String?
1019+
def self?.gets: (?string? separator, ?int limit, ?chomp: boolish) -> String?
1020+
| (int limit, ?chomp: boolish) -> String?
10191021

10201022
# <!--
10211023
# rdoc-file=eval.c
@@ -1027,7 +1029,7 @@ module Kernel : BasicObject
10271029
#
10281030
# global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
10291031
#
1030-
def self?.global_variables: () -> ::Array[Symbol]
1032+
def self?.global_variables: () -> Array[Symbol]
10311033

10321034
# <!--
10331035
# rdoc-file=load.c
@@ -1056,7 +1058,7 @@ module Kernel : BasicObject
10561058
# executed under the given module. In no circumstance will any local variables
10571059
# in the loaded file be propagated to the loading environment.
10581060
#
1059-
def self?.load: (String filename, ?Module | bool) -> bool
1061+
def self?.load: (path filename, ?Module | bool wrap) -> true
10601062

10611063
# <!--
10621064
# rdoc-file=kernel.rb
@@ -1087,8 +1089,8 @@ module Kernel : BasicObject
10871089
# puts enum.next
10881090
# } #=> :ok
10891091
#
1090-
def self?.loop: () { () -> void } -> bot
1091-
| () -> ::Enumerator[nil, bot]
1092+
def self?.loop: () -> Enumerator[nil, untyped]
1093+
| () { () -> void } -> untyped
10921094

10931095
# <!--
10941096
# rdoc-file=io.c
@@ -1165,7 +1167,7 @@ module Kernel : BasicObject
11651167
# gets # Sets $_ to the most recent user input.
11661168
# print # Prints $_.
11671169
#
1168-
def self?.print: (*_ToS args) -> nil
1170+
def self?.print: (*_ToS objects) -> nil
11691171

11701172
# <!--
11711173
# rdoc-file=io.c
@@ -1200,16 +1202,20 @@ module Kernel : BasicObject
12001202
# With no arguments, does nothing.
12011203
#
12021204
def self?.printf: () -> nil
1203-
| (String fmt, *untyped args) -> nil
1204-
| (_Writer io, string fmt, *untyped args) -> nil
1205+
| (String fmt, hash[Symbol, untyped] keywords) -> nil
1206+
| (String fmt, **untyped keywords) -> nil
1207+
| (String fmt, *untyped positional) -> nil
1208+
| (_Writer io, string fmt, hash[Symbol, untyped] keywords) -> nil
1209+
| (_Writer io, string fmt, **untyped keywords) -> nil
1210+
| (_Writer io, string fmt, *untyped positional) -> nil
12051211

12061212
# <!--
12071213
# rdoc-file=proc.c
12081214
# - proc { |...| block } -> a_proc
12091215
# -->
12101216
# Equivalent to Proc.new.
12111217
#
1212-
def self?.proc: () { () -> untyped } -> Proc
1218+
def self?.proc: () { (?) -> untyped } -> Proc
12131219

12141220
# <!--
12151221
# rdoc-file=proc.c
@@ -1218,7 +1224,7 @@ module Kernel : BasicObject
12181224
# Equivalent to Proc.new, except the resulting Proc objects check the number of
12191225
# parameters passed when called.
12201226
#
1221-
def self?.lambda: () { () -> untyped } -> Proc
1227+
def self?.lambda: () { (?) -> untyped } -> Proc
12221228

12231229
# <!--
12241230
# rdoc-file=io.c
@@ -1230,8 +1236,8 @@ module Kernel : BasicObject
12301236
#
12311237
# See IO#putc for important information regarding multi-byte characters.
12321238
#
1233-
def self?.putc: [T < _ToInt] (T chr) -> T
1234-
| (String chr) -> String
1239+
def self?.putc: (String chr) -> String
1240+
| [T < _ToInt] (T chr) -> T
12351241

12361242
# <!--
12371243
# rdoc-file=io.c
@@ -1272,9 +1278,9 @@ module Kernel : BasicObject
12721278
# Kernel#p to be uninterruptible in whole or in part. On CRuby, Kernel#p's
12731279
# writing of data is uninterruptible.
12741280
#
1275-
def self?.p: [T < _Inspect] (T arg0) -> T
1276-
| (_Inspect arg0, _Inspect arg1, *_Inspect rest) -> Array[_Inspect]
1277-
| () -> nil
1281+
def self?.p: () -> nil
1282+
| [T < _Inspect] (T object) -> T
1283+
| [T < _Inspect] (T object1, T object2, *T objects) -> Array[T]
12781284

12791285
# <!--
12801286
# rdoc-file=lib/pp.rb
@@ -1284,9 +1290,9 @@ module Kernel : BasicObject
12841290
#
12851291
# pp returns argument(s).
12861292
#
1287-
def self?.pp: [T] (T arg0) -> T
1288-
| (untyped, untyped, *untyped) -> Array[untyped]
1289-
| () -> nil
1293+
def self?.pp: () -> nil
1294+
| [T < PP::_PrettyPrint] (T object) -> T
1295+
| [T < PP::_PrettyPrint] (T object1, T object2, *T objects) -> Array[T]
12901296

12911297
# <!--
12921298
# rdoc-file=random.c
@@ -1339,7 +1345,8 @@ module Kernel : BasicObject
13391345
# Optional keyword argument `chomp` specifies whether line separators are to be
13401346
# omitted.
13411347
#
1342-
def self?.readline: (?String arg0, ?Integer arg1) -> String
1348+
def self?.readline: (?string? separator, ?int limit, ?chomp: boolish) -> String
1349+
| (int limit, ?chomp: boolish) -> String
13431350

13441351
# <!--
13451352
# rdoc-file=io.c
@@ -1394,7 +1401,8 @@ module Kernel : BasicObject
13941401
# Optional keyword arguments `enc_opts` specify encoding options; see [Encoding
13951402
# options](rdoc-ref:encodings.rdoc@Encoding+Options).
13961403
#
1397-
def self?.readlines: (?String arg0, ?Integer arg1) -> ::Array[String]
1404+
def self?.readlines: (?string? separator, ?int limit, ?chomp: boolish) -> Array[String]
1405+
| (int limit, ?chomp: boolish) -> Array[String]
13981406

13991407
# <!--
14001408
# rdoc-file=lib/rubygems/core_ext/kernel_require.rb
@@ -1412,7 +1420,7 @@ module Kernel : BasicObject
14121420
# The normal `require` functionality of returning false if that file has already
14131421
# been loaded is preserved.
14141422
#
1415-
def self?.require: (String path) -> bool
1423+
def self?.require: (path feature) -> bool
14161424

14171425
# <!--
14181426
# rdoc-file=load.c
@@ -1423,7 +1431,7 @@ module Kernel : BasicObject
14231431
# raised. Returns `true` if the file was loaded and `false` if the file was
14241432
# already loaded before.
14251433
#
1426-
def self?.require_relative: (String feature) -> bool
1434+
def self?.require_relative: (path feature) -> bool
14271435

14281436
# <!--
14291437
# rdoc-file=io.c
@@ -1564,7 +1572,14 @@ module Kernel : BasicObject
15641572
# (snipped)
15651573
# ping
15661574
#
1567-
def self?.select: (::Array[IO] read, ?::Array[IO] write, ?::Array[IO] error, ?Time::_Timeout timeout) -> ::Array[String]
1575+
def self?.select: ([]?, ?[]?, ?[]?, ?nil) -> bot
1576+
| [R < _ToIO] (Array[R] read, ?[]?, ?[]?, ?nil ) -> [Array[R], [], []]
1577+
| [R < _ToIO] (Array[R] read, []?, []?, Time::_Timeout timeout) -> [Array[R], [], []]?
1578+
| [R < _ToIO, W < _ToIO] (Array[R] read, ?Array[W] write, ?[]?, ?nil ) -> [Array[R], Array[W], []]
1579+
| [R < _ToIO, W < _ToIO] (Array[R] read, Array[W] write, []?, Time::_Timeout timeout) -> [Array[R], Array[W], []]?
1580+
| [R < _ToIO, W < _ToIO, E < _ToIO] (Array[R] read, ?Array[W] write, ?Array[E] error, ?nil ) -> [Array[R], Array[W], Array[E]]
1581+
| [R < _ToIO, W < _ToIO, E < _ToIO] (Array[R] read, Array[W] write, Array[E] error, Time::_Timeout timeout) -> [Array[R], Array[W], Array[E]]?
1582+
| (Array[_ToIO]? read, ?Array[_ToIO]? write, ?Array[_ToIO]? error, ?Time_Timeout? timeout) -> [Array[_ToIO], Array[_ToIO], Array[_ToIO]]?
15681583

15691584
# <!--
15701585
# rdoc-file=process.c
@@ -1670,7 +1685,12 @@ module Kernel : BasicObject
16701685
# ">" | boolean | True if the modification time of file1
16711686
# | | is after that of file2
16721687
#
1673-
def self?.test: (String | Integer cmd, String | IO file1, ?String | IO file2) -> (TrueClass | FalseClass | Time | nil | Integer)
1688+
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
1689+
| ('l' | 'r' | 'R' | 'w' | 'W' | 'x' | 'X' | 108 | 114 | 82 | 119 | 87 | 120 | 88, path filename) -> bool
1690+
| ('s' | 115, IO | path filename) -> Integer?
1691+
| ('M' | 'A' | 'C' | 77 | 65 | 67, IO | path file) -> Time
1692+
| ('-' | '=' | '<' | '>' | 45 | 60 | 61 | 62, IO | path file1, IO | path file2) -> bool
1693+
| (String | int cmd, IO | path file1, ?IO | path file2) -> (bool | Integer? | Time)
16741694

16751695
# <!--
16761696
# rdoc-file=vm_eval.c
@@ -1728,7 +1748,7 @@ module Kernel : BasicObject
17281748
# :experimental
17291749
# : Used for experimental features that may change in future releases.
17301750
#
1731-
def self?.warn: (*_ToS msg, ?uplevel: int?, ?category: Warning::category?) -> nil
1751+
def self?.warn: (*_ToS msgs, ?uplevel: int?, ?category: Warning::category | _ToSym | nil) -> nil
17321752

17331753
# <!--
17341754
# rdoc-file=process.c

lib/rbs/test/type_check.rb

Lines changed: 1 addition & 1 deletion
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)