Skip to content

Conversation

@thomasmarshall
Copy link

This fixes a crash with the following:

for
def foo
end

Prism parses this as a ForNode where the index field is a DefNode. That's obviously invalid. The original parser returns a Nil for this cases (and probably others like it). I copied that behavior, checking if the node in the index field is a valid node type or not.

@amomchilov amomchilov force-pushed the desugar-remaining branch 2 times, most recently from d96acf3 to 7f35d5d Compare December 19, 2025 19:25
@amomchilov amomchilov changed the title Fix invalid index in for Fix invalid index in for Jan 7, 2026
};

// Index might be invalid in error recovery cases, match original parser behavior.
if (!isValidTarget(forNode->index)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can invert the true/false and not need the negation

Suggested change
if (!isValidTarget(forNode->index)) {
if (isInvalidTarget(forNode->index)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you could also just use the switch directly, and either return MK::Nil(location.copyWithZeroLength()); or break

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.

2 participants