Bug #16343
closedInconsistent behavior of 'circular argument reference' error
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
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.
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]
Updated by byroot (Jean Boussier) 7 months ago
- Related to Bug #20478: Circular parameter syntax error rules added