[MacRuby] #1177: Hash.each doesn't exit on embedded return
#1177: Hash.each doesn't exit on embedded return -------------------------------+-------------------------------------------- Reporter: dopperman@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: Hash each -------------------------------+-------------------------------------------- i isolated this as best i could. the hash.each loop in the weirdness method does not exit on return. instead, it jumps to the top of the loop and continues to iterate through the hash. replacing the line @map.each do |letters, numbers| with @map.keys.each do |letters| produces the correct behavior. Hash.each and Hash.each_key produce identical results. Not sure this is a high priority since iterating through the Hash.keys array works. class A def initialize(parent) @map = Hash[ 'a', 1, 'b', 2, 'c', 3, 'd', 4] @parent = parent end def test @parent.thread_me_back { weirdness } end def weirdness @map.each do |letters, numbers| # bug lies here puts 'top of loop' if @parent.aborted? puts 'leaving...' return end sleep(1) end end end class B def initialize @abort_signal = false @thread = nil end def run a = A.new(self) a.test sleep(1) @abort_signal = true @thread.join end def thread_me_back(&block) @thread = Thread.new do yield end end def aborted? return @abort_signal end end B.new.run -- Ticket URL: <http://www.macruby.org/trac/ticket/1177> MacRuby <http://macruby.org/>
#1177: Hash.each doesn't exit on embedded return -------------------------------+-------------------------------------------- Reporter: dopperman@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: Hash each -------------------------------+-------------------------------------------- Comment(by dopperman@…): def weirdness map = Hash[ 'a', 1, 'b', 2] #map.keys.each do |a| # this works map.each_key do |a| # bug lies here puts 'leaving...' return end end weirdness this produces: leaving... leaving... -- Ticket URL: <http://www.macruby.org/trac/ticket/1177#comment:1> MacRuby <http://macruby.org/>
#1177: Hash.each doesn't exit on embedded return -------------------------------+-------------------------------------------- Reporter: dopperman@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.10 Component: MacRuby | Resolution: fixed Keywords: Hash each | -------------------------------+-------------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.10 Comment: Thanks for the report, should be fixed in r5253. -- Ticket URL: <http://www.macruby.org/trac/ticket/1177#comment:2> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby