[#104169] [Ruby master Feature#17938] Keyword alternative for boolean positional arguments — matheusrichardt@...

Issue #17938 has been reported by matheusrich (Matheus Richard).

12 messages 2021/06/04

[#104213] [Ruby master Feature#17942] Add a `initialize(public @a, private @b)` shortcut syntax for defining public/private accessors for instance vars — tyler@...

Issue #17942 has been reported by TylerRick (Tyler Rick).

6 messages 2021/06/09

[#104288] [Ruby master Bug#17992] Upstreaming the htmlentities gem into CGI#.(un)escape_html — alexandermomchilov@...

Issue #17992 has been reported by AMomchilov (Alexander Momchilov).

9 messages 2021/06/15

[#104338] [Ruby master Misc#17997] DevelopersMeeting20210715Japan — mame@...

Issue #17997 has been reported by mame (Yusuke Endoh).

10 messages 2021/06/17

[#104361] [Ruby master Bug#18000] have_library doesn't work when ruby is compiled with --disable-shared --disable-install-static-library — jean.boussier@...

Issue #18000 has been reported by byroot (Jean Boussier).

9 messages 2021/06/18

[#104401] [Ruby master Feature#18007] Help developers of C extensions meet requirements in "doc/extension.rdoc" — mike.dalessio@...

Issue #18007 has been reported by mdalessio (Mike Dalessio).

16 messages 2021/06/25

[#104430] [Ruby master Bug#18011] `Method#parameters` is incorrect for forwarded arguments — josh.cheek@...

Issue #18011 has been reported by josh.cheek (Josh Cheek).

12 messages 2021/06/29

[ruby-core:104430] [Ruby master Bug#18011] `Method#parameters` is incorrect for forwarded arguments

From: josh.cheek@...
Date: 2021-06-29 01:02:47 UTC
List: ruby-core #104430
Issue #18011 has been reported by josh.cheek (Josh Cheek).

----------------------------------------
Bug #18011: `Method#parameters` is incorrect for forwarded arguments
https://bugs.ruby-lang.org/issues/18011

* Author: josh.cheek (Josh Cheek)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [arm64-darwin20]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
When asking a method about its parameters, forwarded arguments say they are a rest and a block (`wrapper1` in the example below).
However, when we use that signature, it raises an ArgumentError (`wrapper2` in the example below).
When I add a keyrest to the signature, it works as expected (`wrapper3` in the example below).
So I think forwarded arguments should include a keyrest in the output of `Method#parameters`

```ruby
def wrapped(ord, kw:) = [ord, {kw: kw}]

methods = [
 def wrapper1(...)         = wrapped(...),
 def wrapper2(*r, &b)      = wrapped(*r, &b),
 def wrapper3(*r, **k, &b) = wrapped(*r, **k, &b),
]

methods.each do |name|
  puts File.read(__FILE__)[/#{name}\(.*?\)/]
  puts "  params: #{method(name).parameters.inspect}"
  puts "  result: #{(method(name).call 123, kw: 456 rescue $!).inspect}"
  puts
end
```

Output:

```
wrapper1(...)
  params: [[:rest, :*], [:block, :&]]
  result: [123, {:kw=>456}]

wrapper2(*r, &b)
  params: [[:rest, :r], [:block, :b]]
  result: #<ArgumentError: wrong number of arguments (given 2, expected 1; required keyword: kw)>

wrapper3(*r, **k, &b)
  params: [[:rest, :r], [:keyrest, :k], [:block, :b]]
  result: [123, {:kw=>456}]
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next