From: "jeremyevans0 (Jeremy Evans)" Date: 2022-07-14T20:00:07+00:00 Subject: [ruby-core:109211] [Ruby master Bug#18883] parse.y: trailing comma cannot coexist with star Issue #18883 has been updated by jeremyevans0 (Jeremy Evans). zverok (Victor Shepelev) wrote in #note-1: > As far as I understand, trailing comma is an equivalent of `*_` (unpack the rest and drop it): > ```ruby > x, = [1, 2, 3] > # is the same as > x, *_ = [1, 2, 3] > # put 1 in x, ignore the rest, it is the shortest way to do it > ``` Close. `*_` will set a local variable, and allocate an extra array. `x, = [1, 2, 3]` is actually the same as `x, * = [1, 2, 3]` (same VM instructions). However, this doesn't fully explain the issue, because `x = ` (single assignment) and `x, =` (multiple assignment) are significantly different. It would be better to compare with: ``` x, a = [1, 2, 3] x, a, = [1, 2, 3] x, a, * = [1, 2, 3] ``` All of these result in the same VM instructions, indicating that a trailing comma shouldn't make a difference. That being said, I don't think this is a bug, but I wouldn't be opposed to modifying the parser to support this as a feature, assuming it is doable. ---------------------------------------- Bug #18883: parse.y: trailing comma cannot coexist with star https://bugs.ruby-lang.org/issues/18883#change-98346 * Author: qnighy (Masaki Hara) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- The following code is a syntax error: ```ruby *x, y, = 1, 2 # syntax error, unexpected '=' ``` although the following: ```ruby x, y = 1, 2 # OK x, y, = 1, 2 # OK *x, y = 1, 2 # OK # *x, y, = 1, 2 ``` In my understanding, the trailing comma does nothing unless the lhs becomes otherwise a single assignment. Therefore it is natural to allow the trailing comma whether `*` exists or not. -- https://bugs.ruby-lang.org/ Unsubscribe: