Project

General

Profile

Actions

Feature #21047

open

Change `*nil` to not call `nil.to_a`, for consistency with `**nil`

Added by jeremyevans0 (Jeremy Evans) 2 days ago. Updated 1 day ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:120736]

Description

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

Updated by matz (Yukihiro Matsumoto) 1 day ago

Accepted.

Matz.

Actions

Also available in: Atom PDF

Like2
Like0