Project

General

Profile

Actions

Feature #1303

closed

A name considered a local variable on RHS of an assignment that defines it

Added by tmat (Tomas Matousek) about 15 years ago. Updated almost 13 years ago.

Status:
Rejected
Target version:
[ruby-core:22939]

Description

=begin
The following script defines a method "f" and then a variable "f" by an assignment [1]. There is a reference to "f" on RHS of the assignment. The parser treats this reference as a reference to the local variable "f", not to the method "f", since it has already seen an assignemnt to "f". However, one might expect that within the RHS of an assignment the local variable defined by the assignment should not be visible yet (and indeed its value is nil). The following code should therefore print 123 and and not nil.

def f
123
end

f = f.inspect # [1]

puts f
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0