ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
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:117633] [Ruby master Misc#20441] Should passing keyword args to method_name(*) be an error?
Date: Sun, 21 Apr 2024 08:47:06 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-108041.20240421084705.10397@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20441.20240421082521.10397@ruby-lang.org

Issue #20441 has been updated by ozydingo (Andrew Schwartz).


Why does this conversion to a Hash occur?

I would guess for some sense of backward compatibility with gems / code written in earlier versions of Ruby. But #20440 demonstrates why this compatibility is not achieved. To be clear, I'm not arguing it _should_ be backward compatible, and it isn't; but they why should `*` convert keyword args to a Hash instead of considering it an error?

`super` only comes into play because that's the only time you'll silently pass the converted arg in code that might not be compatible with doing so, such as in the linked example. Without `super` the args are simply unused.

----------------------------------------
Misc #20441: Should passing keyword args to method_name(*) be an error?
https://bugs.ruby-lang.org/issues/20441#change-108041

* Author: ozydingo (Andrew Schwartz)
* Status: Open
----------------------------------------
In the following method:

```rb
def foo(*)
  super
end
```

it is apparently the intended ruby 3 behavior to pass keyword args as a positional Hash to `super`. I believe this is confusing and can lead to hidden and hard-to-discover bugs (e.g. #20440). Since `*` is meant to only represent positional args, should it be an ArgumentError to pass keyword args at all to this method? Similar to how it is an error to pass positions args to `bar(**)`.



-- 
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/

  parent reply	other threads:[~2024-04-21  8:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-21  8:25 [ruby-core:117631] [Ruby master Misc#20441] Should passing keyword args to method_name(*) be an error? ozydingo (Andrew Schwartz) via ruby-core
2024-04-21  8:33 ` [ruby-core:117632] " zverok (Victor Shepelev) via ruby-core
2024-04-21  8:47 ` ozydingo (Andrew Schwartz) via ruby-core [this message]
2024-04-21  8:58 ` [ruby-core:117634] " zverok (Victor Shepelev) via ruby-core
2024-04-21 14:33 ` [ruby-core:117635] " 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.journal-108041.20240421084705.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).