Forum: Ruby-core [ruby-trunk - Bug #7734][Open] Post IF - undefined local variable

C224ec2aa9c0d838fb81255dc089c434?d=identicon&s=25 Sergey Ezhov (sergeyezhov)
on 2013-01-23 13:03
(Received via mailing list)
Issue #7734 has been reported by Sega100500 (Сергей Е).

----------------------------------------
Bug #7734: Post IF - undefined local variable
https://bugs.ruby-lang.org/issues/7734

Author: Sega100500 (Сергей Е)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 1.9.3
ruby -v: 1.9.3p374


hash[:tree] = tree if (tree = _get_path_tree_array(params, path, deep +
1)) && ! tree.empty?

# => undefined local variable or method `tree' for #<Content:0x92d96b0>

but

if (tree = _get_path_tree_array(params, path, deep + 1)) && !
tree.empty?
  hash[:tree] = tree
end

# => WORK FINE!


Content - is a: class Content < ActiveRecord::Base in Ruby on Rails
3.2.11
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Yukihiro Matsumoto) (Guest)
on 2013-01-23 16:14
(Received via mailing list)
Issue #7734 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

The local variables are considered defined *after* the assignments, so
that in above case, tree appears before the assignment is intentionally
left undefined.

Matz.

----------------------------------------
Bug #7734: Post IF - undefined local variable
https://bugs.ruby-lang.org/issues/7734#change-35558

Author: Sega100500 (Сергей Е)
Status: Rejected
Priority: Normal
Assignee:
Category: core
Target version: 1.9.3
ruby -v: 1.9.3p374


hash[:tree] = tree if (tree = _get_path_tree_array(params, path, deep +
1)) && ! tree.empty?

# => undefined local variable or method `tree' for #<Content:0x92d96b0>

but

if (tree = _get_path_tree_array(params, path, deep + 1)) && !
tree.empty?
  hash[:tree] = tree
end

# => WORK FINE!


Content - is a: class Content < ActiveRecord::Base in Ruby on Rails
3.2.11
This topic is locked and can not be replied to.