Project

General

Profile

Actions

Bug #16343

closed

Inconsistent behavior of 'circular argument reference' error

Added by ibylich (Ilya Bylich) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.0dev (2019-11-04T16:32:26Z trunk a087e027bf) [x86_64-darwin19]
[ruby-core:95799]

Description

The following code gives a syntax error:

m { |foo = proc { || foo }|  }
# => SyntaxError (-e:14: circular argument reference - foo)

But this code is valid:

m { |foo = proc { |bar| foo }|  }

Is it intentional? foo becomes a proc that returns itself, so there must be a circular dependency


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #20478: Circular parameter syntax error rulesClosedActions

Updated by jeremyevans0 (Jeremy Evans) about 5 years ago

On Ruby 2.2-2.6, there is a warning instead of an error in the first case, but I think that is invalid. The reason for the warning/error is to complain about this code:

def a(b=b)
  b
end

Here, a would return nil, because of how the default argument values are handled. The reason the warning was added is because in Ruby 2.1 and below, calling a with no arguments would call the b method to get the value for the b argument.

m { |foo = proc { || foo }| } is not a case I think we should warn about, since it doesn't have the same issue. m { |foo = proc { || foo }.call| } could have the same issue, but it seems unlikely to occur in real world code.

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Status changed from Open to Closed

Applied in changeset git|ed90ec3e0d8ff7789569b40ba36d3b3ce0e706e6.


Clear current argument name at empty block argument [Bug #16343]

Actions #3

Updated by byroot (Jean Boussier) 6 months ago

  • Related to Bug #20478: Circular parameter syntax error rules added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0