Project

General

Profile

Actions

Bug #20478

open

Circular parameter syntax error rules

Added by kddnewton (Kevin Newton) 11 days ago. Updated 6 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:117812]

Description

I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes

These cases are not syntax errors:

def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

  • Syntax error is raised if the parameter is ever read in its default value at any scope depth
  • Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #16343: Inconsistent behavior of 'circular argument reference' errorClosedActions

Updated by nobu (Nobuyoshi Nakada) 10 days ago

Given that these Procs are only created if the argument bar is not assigned, should they all be syntax errors?

Updated by kddnewton (Kevin Newton) 9 days ago

Yes, I very much think they should all be syntax errors.

Updated by nobu (Nobuyoshi Nakada) 8 days ago

Even this should be a syntax error?

def foo(bar = ->(baz = bar) {}) end

That means it needs to manage the list of yet-unusable variables, not only tracking single variable.

Updated by kddnewton (Kevin Newton) 6 days ago

I figured that was already happening for the "unused" warning.

Actions #5

Updated by byroot (Jean Boussier) 6 days ago

  • Related to Bug #16343: Inconsistent behavior of 'circular argument reference' error added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0