Project

General

Profile

Actions

Feature #8600

closed

Recognize variables declared in if modifier at end of line

Feature #8600: Recognize variables declared in if modifier at end of line

Added by rudolph9 (Kurt Rudolph) almost 13 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:55783]

Description

=begin
2.0.0 (main):0 > .ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
2.0.0 (main):0 > ([0,1,2])[i] = 1.0 if i = ['seconds'].find_index('seconds')
NameError: undefined local variable or method i' for main:Object from (pry):1:in pry'

Is it possible to get rid of this kind of error? Especially since it doesn't matter what the value of the variable is so long as it's defined.

2.0.0 (main):0 > i = 10000
=> 10000
2.0.0 (main):0 > ([0,1,2])[i] = 1.0 if i = ['seconds'].find_index('seconds')
=> 1.0
=end


Related issues 3 (0 open3 closed)

Is duplicate of Ruby - Feature #1141: assignment of variable in "right" if statement failsRejectedActions
Is duplicate of Ruby - Feature #4965: The problem of "print line if line = DATA.gets"Rejectedmatz (Yukihiro Matsumoto)Actions
Is duplicate of Ruby - Bug #6132: Assignments don't happen correctly in "if" modifiersRejectedActions

Updated by rosenfeld (Rodrigo Rosenfeld Rosas) almost 13 years ago Actions #1 [ruby-core:55785]

A long-time +1, but if I remember correctly Matz doesn't want this because it could introduce backward incompatibility...

Updated by rosenfeld (Rodrigo Rosenfeld Rosas) almost 13 years ago Actions #2 [ruby-core:55786]

Or maybe because it would be too complex to change the parser to support that? Now I'm not sure about the reasons...

Updated by matz (Yukihiro Matsumoto) almost 13 years ago Actions #3 [ruby-core:55790]

  • Description updated (diff)
  • Status changed from Open to Rejected

Variables are declared in the order of appearance. I don't want to introduce exceptions.

Matz.

Updated by nobu (Nobuyoshi Nakada) almost 13 years ago Actions #4 [ruby-core:55792]

  • Description updated (diff)
Actions

Also available in: PDF Atom