Project

General

Profile

Bug #16343

Inconsistent behavior of 'circular argument reference' error

Added by ibylich (Ilya Bylich) 3 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
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

Updated by jeremyevans0 (Jeremy Evans) 3 months 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.

#2

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

Applied in changeset git|ed90ec3e0d8ff7789569b40ba36d3b3ce0e706e6.


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

Also available in: Atom PDF