Skip to content

Conversation

@Earlopain
Copy link
Contributor

Fixes [#Bug 21660], followup to #3674

@tompng
Copy link
Member

tompng commented Nov 1, 2025

Instead of rejecting at every possible token/node that appears before EQUAL of syntax-invalid endless def, How about simply check at accept1(parse, PM_TOKEN_EQUAL) like this?

case PM_TOKEN_KEYWORD_DEF: {
  ...
  bool accept_endless_def;
  switch (parser->current.type) {
    case PM_TOKEN_PARENTHESIS_LEFT: { // `def f(a)`, `def f(*a)`, etc
      accept_endless_def = true;
      ...
    }
    case PM_CASE_PARAMETER: { // `def f a`, `def f *a`, `def f a, (b)`, etc
      accept_endless_def = false;
      ...
    }
    default: { // def f 
      accept_endless_def = true;
      ...
    }
  }

  if (accept1(parser, PM_TOKEN_EQUAL)) {
    // `def f(PARAMETERS) =` and `def f =` can be endless method definition
    // Raise error for `def f [PARAMETERS] =`
  }
}

Fixes [#Bug 21660], followup to ruby#3674

Co-Authored-By: tomoya ishida <[email protected]>
@Earlopain Earlopain force-pushed the endless-command-destructuring branch from c2be206 to fb445a4 Compare November 1, 2025 20:45
@Earlopain
Copy link
Contributor Author

No clue why I made it so complicated, your suggestion is much nicer. I applied it

@kddnewton kddnewton merged commit a156df0 into ruby:main Nov 6, 2025
62 checks passed
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.

3 participants