From: "matz (Yukihiro Matsumoto) via ruby-core" Date: 2025-01-19T23:12:57+00:00 Subject: [ruby-core:120739] [Ruby master Feature#21047] Change `*nil` to not call `nil.to_a`, for consistency with `**nil` 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/