Project

General

Profile

Actions

Bug #22177

open

Prism rejects a nested destructuring target in a for loop index, while parse.y accepts it

Bug #22177: Prism rejects a nested destructuring target in a for loop index, while parse.y accepts it

Added by shugo (Shugo Maeda) about 10 hours ago. Updated about 10 hours ago.

Status:
Open
Assignee:
Target version:
-
ruby -v:
ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux]
[ruby-core:125927]

Description

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

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

Updated by shugo (Shugo Maeda) about 10 hours ago Actions #1 [ruby-core:125928]

  • Assignee set to prism

I've created a pull request: https://github.com/ruby/prism/pull/4156

Actions

Also available in: PDF Atom