* [ruby-core:120736] [Ruby master Feature#21047] Change `*nil` to not call `nil.to_a`, for consistency with `**nil`
@ 2025-01-19 7:48 jeremyevans0 (Jeremy Evans) via ruby-core
2025-01-19 23:12 ` [ruby-core:120739] " matz (Yukihiro Matsumoto) via ruby-core
0 siblings, 1 reply; 2+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2025-01-19 7:48 UTC (permalink / raw)
To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)
Issue #21047 has been reported by jeremyevans0 (Jeremy Evans).
----------------------------------------
Feature #21047: Change `*nil` to not call `nil.to_a`, for consistency with `**nil`
https://bugs.ruby-lang.org/issues/21047
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
----------------------------------------
In Ruby 3.3, we started accepting `**nil` for keyword splats. This does not call `nil.to_hash`, unlike other uses of `**` for splatting. This made `**nil` handling inconsistent with `*nil` handling, as `*nil` historically has called `nil.to_a`. I propose we make them consistent, by having `*nil` not call `nil.to_a`.
Advantage: In addition to more consistent behavior with `**nil`, making `*nil` not call `nil.to_a` opens up new a optimization opportunity, since it allows `*nil` to be optimized to not allocate an array, similar to how `**nil` is already optimized to not allocate a hash.
Disadvantage: Minor backwards compatibility breakage, though it is very unlikely any code other than test code will break, because overriding `nil.to_a` to return anything other than the empty array would likely break any large Ruby application.
I've submitted a pull request to implement this: https://github.com/ruby/ruby/pull/12597
--
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/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:120739] [Ruby master Feature#21047] Change `*nil` to not call `nil.to_a`, for consistency with `**nil`
2025-01-19 7:48 [ruby-core:120736] [Ruby master Feature#21047] Change `*nil` to not call `nil.to_a`, for consistency with `**nil` jeremyevans0 (Jeremy Evans) via ruby-core
@ 2025-01-19 23:12 ` matz (Yukihiro Matsumoto) via ruby-core
0 siblings, 0 replies; 2+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2025-01-19 23:12 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #21047 has been updated by matz (Yukihiro Matsumoto).
Accepted.
Matz.
----------------------------------------
Feature #21047: Change `*nil` to not call `nil.to_a`, for consistency with `**nil`
https://bugs.ruby-lang.org/issues/21047#change-111570
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
----------------------------------------
In Ruby 3.3, we started accepting `**nil` for keyword splats. This does not call `nil.to_hash`, unlike other uses of `**` for splatting. This made `**nil` handling inconsistent with `*nil` handling, as `*nil` historically has called `nil.to_a`. I propose we make them consistent, by having `*nil` not call `nil.to_a`.
Advantage: In addition to more consistent behavior with `**nil`, making `*nil` not call `nil.to_a` opens up new a optimization opportunity, since it allows `*nil` to be optimized to not allocate an array, similar to how `**nil` is already optimized to not allocate a hash.
Disadvantage: Minor backwards compatibility breakage, though it is very unlikely any code other than test code will break, because overriding `nil.to_a` to return anything other than the empty array would likely break any large Ruby application.
I've submitted a pull request to implement this: https://github.com/ruby/ruby/pull/12597
--
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/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-19 23:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-19 7:48 [ruby-core:120736] [Ruby master Feature#21047] Change `*nil` to not call `nil.to_a`, for consistency with `**nil` jeremyevans0 (Jeremy Evans) via ruby-core
2025-01-19 23:12 ` [ruby-core:120739] " matz (Yukihiro Matsumoto) via ruby-core
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).