[ruby-core:125927] [Ruby Bug#22177] Prism rejects a nested destructuring target in a for loop index, while parse.y accepts it
Issue #22177 has been reported by shugo (Shugo Maeda). ---------------------------------------- Bug #22177: Prism rejects a nested destructuring target in a for loop index, while parse.y accepts it https://bugs.ruby-lang.org/issues/22177 * Author: shugo (Shugo Maeda) * Status: Open * ruby -v: ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ## Summary When the index of a `for` loop is a multiple-assignment target whose first element is itself a parenthesized target (for example `(a, b), c`), Prism reports a syntax error, but parse.y accepts it. The same target works in a normal multiple assignment in both parsers, so the difference is specific to the `for` loop index. ## Reproduction ```ruby for (a, b), c in [[[1, 2], 3]] do p [a, b, c] end ``` ### parse.y (--parser=parse.y) Accepted. Prints: ``` [1, 2, 3] ``` ### Prism (default, --parser=prism) Rejected: ```
1 | for (a, b), c in [[[1, 2], 3]] do | ^~~~~ unexpected write target
--
https://bugs.ruby-lang.org/
Issue #22177 has been updated by shugo (Shugo Maeda). Assignee set to prism I've created a pull request: https://github.com/ruby/prism/pull/4156 ---------------------------------------- Bug #22177: Prism rejects a nested destructuring target in a for loop index, while parse.y accepts it https://bugs.ruby-lang.org/issues/22177#change-117896 * Author: shugo (Shugo Maeda) * Status: Open * Assignee: prism * ruby -v: ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ## Summary When the index of a `for` loop is a multiple-assignment target whose first element is itself a parenthesized target (for example `(a, b), c`), Prism reports a syntax error, but parse.y accepts it. The same target works in a normal multiple assignment in both parsers, so the difference is specific to the `for` loop index. ## Reproduction ```ruby for (a, b), c in [[[1, 2], 3]] do p [a, b, c] end ``` ### parse.y (--parser=parse.y) Accepted. Prints: ``` [1, 2, 3] ``` ### Prism (default, --parser=prism) Rejected: ```
1 | for (a, b), c in [[[1, 2], 3]] do | ^~~~~ unexpected write target
--
https://bugs.ruby-lang.org/
Issue #22177 has been updated by shugo (Shugo Maeda). Status changed from Open to Closed Fixed in https://github.com/ruby/ruby/commit/bc4960996781ff50657a0cdc6c6f30d999151f90 ---------------------------------------- Bug #22177: Prism rejects a nested destructuring target in a for loop index, while parse.y accepts it https://bugs.ruby-lang.org/issues/22177#change-117904 * Author: shugo (Shugo Maeda) * Status: Closed * Assignee: prism * ruby -v: ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ## Summary When the index of a `for` loop is a multiple-assignment target whose first element is itself a parenthesized target (for example `(a, b), c`), Prism reports a syntax error, but parse.y accepts it. The same target works in a normal multiple assignment in both parsers, so the difference is specific to the `for` loop index. ## Reproduction ```ruby for (a, b), c in [[[1, 2], 3]] do p [a, b, c] end ``` ### parse.y (--parser=parse.y) Accepted. Prints: ``` [1, 2, 3] ``` ### Prism (default, --parser=prism) Rejected: ```
1 | for (a, b), c in [[[1, 2], 3]] do | ^~~~~ unexpected write target
--
https://bugs.ruby-lang.org/
participants (1)
-
shugo (Shugo Maeda)