Project

General

Profile

Actions

Bug #21623

closed

Endless method definition without parenthesis is wrongly accepted in Prism

Bug #21623: Endless method definition without parenthesis is wrongly accepted in Prism

Added by tompng (tomoya ishida) 22 days ago. Updated 17 days ago.

Status:
Closed
Assignee:
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-10-02T03:48:32Z master 88222caaa9) +PRISM [x86_64-linux]
[ruby-core:123383]

Description

These are syntax error in parse.y but accepted in Prism

def f x: = 1
def f ... = 1
def f * = 1
def f ** = 1
def f & = 1
def f *a = 1
def f **a = 1
def f &a = 1

Updated by alanwu (Alan Wu) 22 days ago Actions #1 [ruby-core:123384]

  • Assignee set to prism

Updated by Earlopain (Earlopain _) 17 days ago Actions #3

  • Status changed from Open to Closed

Applied in changeset git|b8f8d646a64f883652b44780c4174a85f98d1c82.


[ruby/prism] For these special cases, there exists no optional argument type. Since a endless method is started with =, there was ambiguity here. We have to simply reject these in all cases.

This adds a new error for the following reason:

  • def foo arg = nil is interpreted as a normal method call with optional arg without matching end
  • def foo *arg = nil; end is interpreted as a endless method call that has body nil with extraneous end

def foo *arg = nil is somewhere inbetween and I don't know how to otherwise indicate the error.
Now the second case above also shows the newly added error message.

Fixes [Bug #21623]

https://github.com/ruby/prism/commit/e1910d4492

Actions

Also available in: PDF Atom