Skip to content

Commit

Permalink
Merge pull request #1444 from sampersand/swesterman/23-08-18/kernel-c…
Browse files Browse the repository at this point in the history
…ontrol-flow

Updated control flow type definitions
  • Loading branch information
soutaro authored Aug 22, 2023
2 parents 55120ab + 706c95f commit 4f40cf4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
21 changes: 10 additions & 11 deletions core/kernel.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ module Kernel : BasicObject
# 4. Therefore you should use spawn() instead of fork().
#
def self?.fork: () -> Integer?
| () { () -> untyped } -> Integer?
| () { () -> void } -> Integer

def initialize_copy: (self object) -> self

Expand Down Expand Up @@ -691,7 +691,7 @@ module Kernel : BasicObject
# Terminate execution immediately, effectively by calling `Kernel.exit(false)`.
# If *msg* is given, it is written to STDERR prior to terminating.
#
def self?.abort: (?String msg) -> bot
def self?.abort: (?string msg) -> bot

# <!--
# rdoc-file=eval_jump.c
Expand All @@ -712,7 +712,7 @@ module Kernel : BasicObject
#
# goodbye cruel world
#
def self?.at_exit: () { () -> untyped } -> Proc
def self?.at_exit: () { () -> void } -> Proc

# <!--
# rdoc-file=load.c
Expand Down Expand Up @@ -795,8 +795,7 @@ module Kernel : BasicObject
# at_exit function
# in finalizer
#
def self?.exit: () -> bot
| (?Integer | TrueClass | FalseClass status) -> bot
def self?.exit: (?int | bool status) -> bot

# <!--
# rdoc-file=process.c
Expand All @@ -807,7 +806,7 @@ module Kernel : BasicObject
#
# Process.exit!(true)
#
def self?.exit!: (?Integer | TrueClass | FalseClass status) -> bot
def self?.exit!: (?int | bool status) -> bot

# <!-- rdoc-file=eval.c -->
# With no arguments, raises the exception in `$!` or raises a RuntimeError if
Expand All @@ -828,8 +827,8 @@ module Kernel : BasicObject
# raise ArgumentError, "No parameters", caller
#
def self?.fail: () -> bot
| (String message, ?cause: Exception?) -> bot
| (_Exception exception, ?untyped message, ?::Array[String] backtrace, ?cause: Exception?) -> bot
| (string message, ?cause: Exception?) -> bot
| (_Exception exception, ?_ToS? message, ?nil | String | Array[String] backtrace, ?cause: Exception?) -> bot

# <!--
# rdoc-file=eval.c
Expand Down Expand Up @@ -988,7 +987,7 @@ module Kernel : BasicObject
# puts enum.next
# } #=> :ok
#
def self?.loop: () { (nil) -> untyped } -> bot
def self?.loop: () { () -> void } -> bot
| () -> ::Enumerator[nil, bot]

# <!--
Expand Down Expand Up @@ -1550,7 +1549,7 @@ module Kernel : BasicObject
# sleep 1.9 #=> 2
# Time.new #=> 2008-03-08 19:56:22 +0900
#
def self?.sleep: () -> bot
def self?.sleep: (?nil) -> bot
| ((Integer | Float | _Divmod) duration) -> Integer

interface _Divmod
Expand Down Expand Up @@ -1650,7 +1649,7 @@ module Kernel : BasicObject
# optional second parameter supplies a return value for the `catch` block, which
# otherwise defaults to `nil`. For examples, see Kernel::catch.
#
def self?.throw: (Object tag, ?untyped obj) -> bot
def self?.throw: (untyped tag, ?untyped obj) -> bot

# <!--
# rdoc-file=warning.rb
Expand Down
45 changes: 44 additions & 1 deletion test/stdlib/Kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ def test_abort
abort 'foo'
rescue SystemExit
end

begin
abort ToStr.new
rescue SystemExit
end
end

def test_at_exit
Expand Down Expand Up @@ -387,6 +392,11 @@ def test_exit
rescue SystemExit
end

begin
exit ToInt.new
rescue SystemExit
end

begin
exit true
rescue SystemExit
Expand All @@ -413,6 +423,16 @@ def test_fail
rescue RuntimeError
end

begin
fail 'error', cause: nil
rescue RuntimeError
end

begin
fail 'error', cause: RuntimeError.new("oops!")
rescue RuntimeError
end

test_error = Class.new(StandardError)
begin
fail test_error
Expand All @@ -425,7 +445,27 @@ def test_fail
end

begin
fail test_error, 'a', ['1.rb, 2.rb']
fail test_error, ToS.new, ['1.rb, 2.rb']
rescue test_error
end

begin
fail test_error, 'b', '1.rb'
rescue test_error
end

begin
fail test_error, 'b', nil
rescue test_error
end

begin
fail test_error, 'b', cause: RuntimeError.new("?")
rescue test_error
end

begin
fail test_error, 'b', cause: nil
rescue test_error
end

Expand Down Expand Up @@ -588,6 +628,9 @@ def o.divmod(i)
[0.001, 0.001]
end
sleep o

omit_if(RUBY_VERSION < "3.3.0")
sleep nil
end

def test_syscall
Expand Down

0 comments on commit 4f40cf4

Please sign in to comment.