Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Kernel.fail is able to accept keyword arguments #1567

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Oct 15, 2023

For compatibility, Kernel.fail (as kwnon as raise) is able to accept keyword arguments. It's not undocumented in the Ruby language documentation, but it's surely mentioned in the Ruby's spec.

refs: https://github.com/ruby/ruby/blob/v3_2_0/spec/ruby/shared/kernel/raise.rb#L38-L50

For compatibility, Kernel.fail (as kwnon as raise) is able to accept
keyword arguments.  It's not undocumented in the Ruby language
documentation, but it's surely mentioned in the Ruby's spec.

refs: https://github.com/ruby/ruby/blob/v3_2_0/spec/ruby/shared/kernel/raise.rb#L38-L50
@@ -844,6 +844,7 @@ module Kernel : BasicObject
def self?.fail: () -> bot
| (string message, ?cause: Exception?) -> bot
| (_Exception exception, ?_ToS? message, ?String | Array[String] | nil backtrace, ?cause: Exception?) -> bot
| (_Exception exception, ?cause: Exception?, **untyped) -> bot
Copy link
Member

@soutaro soutaro Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                | (_Exception exception, ?String | Array[String] | nil backtrace, ?cause: Exception?, **untyped) -> bot

🗑️ Withdraw this suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Kernel.raise accepts keyword arguments only if no positional arguments. So it's not good to add backtrace argument here.

irb(main):007> raise Exception, foo: 1
(irb):7:in `<main>': {:foo=>1} (Exception)
	from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):008> raise Exception, '', foo: 1
(irb):8:in `set_backtrace': backtrace must be Array of String (TypeError)
	from (irb):8:in `raise'
	from (irb):8:in `<main>'
	from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):009> raise Exception, '', [], foo: 1
(irb):9:in `raise': wrong number of arguments (given 4, expected 0..3) (ArgumentError)
	from (irb):9:in `<main>'
	from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):010> raise Exception, [], foo: 1
(irb):10:in `set_backtrace': backtrace must be Array of String (TypeError)
	from (irb):10:in `raise'
	from (irb):10:in `<main>'
	from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
	from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'

@soutaro soutaro added this to the RBS 3.3 milestone Oct 16, 2023
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@soutaro soutaro added this pull request to the merge queue Oct 16, 2023
Merged via the queue into ruby:master with commit 8fe3c32 Oct 16, 2023
@tk0miya tk0miya deleted the update_Kernel.raise branch October 16, 2023 12:51
@soutaro soutaro added the Released PRs already included in the released version label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released PRs already included in the released version
Development

Successfully merging this pull request may close these issues.

2 participants