From: "ozydingo (Andrew Schwartz) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "ozydingo (Andrew Schwartz)" <noreply@ruby-lang.org>
Subject: [ruby-core:117624] [Ruby master Bug#20440] `super` from child class passing keyword arg as Hash if in a method with passthrough args called from base class
Date: Sat, 20 Apr 2024 09:01:00 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-20440.20240420090059.10397@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20440.20240420090059.10397@ruby-lang.org
Issue #20440 has been reported by ozydingo (Andrew Schwartz).
----------------------------------------
Bug #20440: `super` from child class passing keyword arg as Hash if in a method with passthrough args called from base class
https://bugs.ruby-lang.org/issues/20440
* Author: ozydingo (Andrew Schwartz)
* Status: Open
* ruby -v: 3.3.0
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Apologies for the verbose title, but that's the specific set of conditions that AFAICT are required to reproduce the bug!
Here's the simplest setup I can reproduce:
```rb
class Base
def foo(*args, x: 1)
puts "Base: calling foo with args: #{args}, x: #{x}"
end
def foo!(x: 1)
puts "Base: calling foo! with x: #{x}"
foo(x: x)
end
end
class Child < Base
def foo(*)
puts "Child: calling foo"
super
end
end
```
When I call `Child.new.foo!`, I expect it to call the base class method `foo!`, which will use the default keyword arg `x: 1`; then the child method `foo` with `x: 1`, and finally the base method `foo` with `x: 1`. However, this is not what I observe:
```rb
Child.new.foo!
Base: calling foo! with x: 1
Child: calling foo
Base: calling foo with args: [{:x=>1}], x: 1
```
So when the child `foo` method called `super`, it passed not only `x: 1` as a keyword arg, but *also* `{x: 1}` as a Hash positional arg to the super method.
This is breaking my upgrade to Ruby 3.0 as I have a similar setup but without the `*args` param, this I am getting the error "wrong number of arguments (given 1, expected 0)".
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/
next parent reply other threads:[~2024-04-20 9:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-20 9:01 ozydingo (Andrew Schwartz) via ruby-core [this message]
2024-04-20 9:12 ` [ruby-core:117625] [Ruby master Bug#20440] `super` from child class passing keyword arg as Hash if in a method with passthrough args called from base class ozydingo (Andrew Schwartz) via ruby-core
2024-04-20 9:55 ` [ruby-core:117626] " nobu (Nobuyoshi Nakada) via ruby-core
2024-04-20 11:04 ` [ruby-core:117627] " Eregon (Benoit Daloze) via ruby-core
2024-04-21 7:02 ` [ruby-core:117628] " ozydingo (Andrew Schwartz) via ruby-core
2024-04-21 7:44 ` [ruby-core:117629] [Ruby master Bug#20440] `super` from child class duplicating a keyword argument as a positional Hash zverok (Victor Shepelev) via ruby-core
2024-04-21 8:16 ` [ruby-core:117630] " ozydingo (Andrew Schwartz) via ruby-core
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-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-20440.20240420090059.10397@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
--cc=noreply@ruby-lang.org \
--cc=ruby-core@ml.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 read-only IMAP folder(s) and NNTP newsgroup(s).