Skip to content

Accept a nested target as the first for loop index#4156

Open
shugo wants to merge 1 commit into
ruby:mainfrom
shugo:fix/for-nested-mlhs
Open

Accept a nested target as the first for loop index#4156
shugo wants to merge 1 commit into
ruby:mainfrom
shugo:fix/for-nested-mlhs

Conversation

@shugo

@shugo shugo commented Jul 4, 2026

Copy link
Copy Markdown
Member

A for loop index may be a multiple-assignment target whose first element is itself a parenthesized (nested) target, e.g.

for (a, b), c in 1..10
end

CRuby's parse.y accepts this, and a plain multiple assignment with the same target ((a, b), c = ...) is accepted, but Prism rejected it with "unexpected write target".

When parse_parentheses finishes the first (a, b), it validates the multi-target it produced. In a for index it only allowed the target to be followed by in, so a following , (which continues the index target list) fell through to the "not a statement level" error. Allow a comma there as well.

A `for` loop index may be a multiple-assignment target whose first
element is itself a parenthesized (nested) target, e.g.

    for (a, b), c in 1..10
    end

CRuby's parse.y accepts this, and a plain multiple assignment with the
same target (`(a, b), c = ...`) is accepted, but Prism rejected it with
"unexpected write target".

When parse_parentheses finishes the first `(a, b)`, it validates the
multi-target it produced. In a `for` index it only allowed the target
to be followed by `in`, so a following `,` (which continues the index
target list) fell through to the "not a statement level" error. Allow
a comma there as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant