Odd break behavior?

T

Thomas E Enebo

Run the code snippet below:

class A
def outer
inner do
break
end
end

def inner
while true
yield
end
puts "Should never appear"
end
end

['something'].each do
A.new.outer
puts "1"
end

A.new.outer
puts "2"

Then comment out the something each block and rerun it. The first
run will look like:
1
2

The second run will look like:
Should never appear
2

For consistencies sake, I would have expected the first run to look like:
1
Should never appear
2

By virtue of previously calling outer in a block the second call to outer
now has different behavior (even though to me they look totally unrelated).
Can someone explain why this is?

-Tom
 
T

Thomas E Enebo

In message "Re: Odd break behavior?"

| Run the code snippet below:

<snip>

It seems to be a bug. Thank you for finding it. It's too complex to
fix it in a minute.

I am trying to determine the proper behavior to fix break in jruby.
Was what I expected the proper behavior?

-Tom
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Odd break behavior?"

| I am trying to determine the proper behavior to fix break in jruby.
|Was what I expected the proper behavior?

"break" should always terminate the lexically innermost loop or block.
In this case, invocation of "inner" should have been terminated. A
bug cause termination of while loop (the closest loop in dynamic call
graph) in the definition of "inner" erroneously.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,664
Latest member
RoseannBow

Latest Threads

Top