From: "yui-knk (Kaneko Yuichiro)" <noreply@ruby-lang.org>
To: ruby-dev@neon.ruby-lang.org
Subject: [ruby-dev:51202] [Ruby master Bug#19132] `**` を引数に指定すると no anonymous keyword rest parameter になる
Date: Thu, 17 Nov 2022 09:09:06 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-100149.20221117090906.82@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-19132.20221116051519.82@ruby-lang.org>
Issue #19132 has been updated by yui-knk (Kaneko Yuichiro).
* UnboundMethod#parametersなどでは ** という変数名が見えている
* `DVAR@1:6-1:8 nil` で `**`を表現するよりは、`kwrest: (DVAR@1:6-1:8 :**)`で表現したほうが理解がしやすい
という点からRubyVM::AST側でも `**` が取得できるというふうに修正し test/ruby/test_ast.rb のexpectationを更新するのがよいと思います。
また調べたところ、議論になっているtest caseが追加されたのが https://github.com/ruby/ruby/commit/fa41a7b2608#diff-7db75141987f9cf709ba4cb68969d3bc97b0de8dfe175d845df2f3de2b91cae6R320 で、Add support for anonymous rest and keyword rest argument forwarding (https://github.com/ruby/ruby/commit/f53dfab95c3)のほうがあとであることもあり、expectationを更新することに前向きです。
anonymousでない場合:
```ruby
pp RubyVM::AbstractSyntaxTree.parse("def a(**a) end")
#=> (SCOPE@1:0-1:14
tbl: []
args: nil
body:
(DEFN@1:0-1:14
mid: :a
body:
(SCOPE@1:0-1:14
tbl: [:a]
args:
(ARGS@1:6-1:9
pre_num: 0
pre_init: nil
opt: nil
first_post: nil
post_num: 0
post_init: nil
rest: nil
kw: nil
kwrest: (DVAR@1:6-1:9 :a)
block: nil)
body: nil)))
```
anonymousで、`**`を隠す場合:
```ruby
pp RubyVM::AbstractSyntaxTree.parse("def a(**) end")
#=> (SCOPE@1:0-1:13
tbl: []
args: nil
body:
(DEFN@1:0-1:13
mid: :a
body:
(SCOPE@1:0-1:13
tbl: [nil]
args:
(ARGS@1:6-1:8
pre_num: 0
pre_init: nil
opt: nil
first_post: nil
post_num: 0
post_init: nil
rest: nil
kw: nil
kwrest: (DVAR@1:6-1:8 nil)
block: nil)
body: nil)))
```
anonymousで、`**`を隠さない場合:
```ruby
pp RubyVM::AbstractSyntaxTree.parse("def a(**) end")
#=> (SCOPE@1:0-1:13
tbl: []
args: nil
body:
(DEFN@1:0-1:13
mid: :a
body:
(SCOPE@1:0-1:13
tbl: [:**]
args:
(ARGS@1:6-1:8
pre_num: 0
pre_init: nil
opt: nil
first_post: nil
post_num: 0
post_init: nil
rest: nil
kw: nil
kwrest: (DVAR@1:6-1:8 :**)
block: nil)
body: nil)))
```
----------------------------------------
Bug #19132: `**` を引数に指定すると no anonymous keyword rest parameter になる
https://bugs.ruby-lang.org/issues/19132#change-100149
* Author: tommy (Masahiro Tomita)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0preview3 (2022-11-14) [arm64-darwin21]
* Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED
----------------------------------------
Ruby 3.2.0-preview3 で次のスクリプトを実行するとエラーになります。
```ruby
def hoge(a, *, k: nil, **)
foo(*, **)
end
```
```
% ruby hoge.rb
hoge.rb:2: no anonymous keyword rest parameter
```
次のようにキーワードパラメータが `**` だけであればエラーになりませんでした。
```ruby
def hoge(a, *, **)
foo(*, **)
end
```
--
https://bugs.ruby-lang.org/
prev parent reply other threads:[~2022-11-17 9:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 5:15 [ruby-dev:51196] " tommy (Masahiro Tomita)
2022-11-16 14:16 ` [ruby-dev:51197] " shugo (Shugo Maeda)
2022-11-16 23:03 ` [ruby-dev:51198] " shugo (Shugo Maeda)
2022-11-17 3:23 ` [ruby-dev:51199] " nobu (Nobuyoshi Nakada)
2022-11-17 3:32 ` [ruby-dev:51200] " shugo (Shugo Maeda)
2022-11-17 8:52 ` [ruby-dev:51201] " shugo (Shugo Maeda)
2022-11-17 9:09 ` yui-knk (Kaneko Yuichiro) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-100149.20221117090906.82@ruby-lang.org \
--to=noreply@ruby-lang.org \
--cc=ruby-dev@neon.ruby-lang.org \
--cc=ruby-dev@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).