Forum: Ruby Odd break behavior?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Thomas E Enebo (Guest)
on 2006-02-18 18:43
(Received via mailing list)
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
Yukihiro M. (Guest)
on 2006-02-18 19:05
(Received via mailing list)
Hi,

In message "Re: Odd break behavior?"
    on Sun, 19 Feb 2006 01:40:48 +0900, Thomas E Enebo 
<removed_email_address@domain.invalid>
writes:

|  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.

							matz.
Thomas E Enebo (Guest)
on 2006-02-18 19:17
(Received via mailing list)
On Sun, 19 Feb 2006, Yukihiro M. defenestrated me:
> In message "Re: Odd break behavior?"
>     on Sun, 19 Feb 2006 01:40:48 +0900, Thomas E Enebo 
<removed_email_address@domain.invalid> writes:
>
> |  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
ts (Guest)
on 2006-02-18 20:05
(Received via mailing list)
>>>>> "Y" == Yukihiro M. <removed_email_address@domain.invalid> writes:

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

moulon% diff -u eval.c~ eval.c
--- eval.c~	2005-12-20 14:41:47.000000000 +0100
+++ eval.c	2006-02-18 18:46:29.000000000 +0100
@@ -752,7 +752,7 @@
 #define BLOCK_LAMBDA  2

 static struct BLOCK *ruby_block;
-static unsigned long block_unique = 0;
+static unsigned long block_unique = 1;

 #define PUSH_BLOCK(v,b) do {		\
     struct BLOCK _block;		\
moulon%

 no ?


Guy Decoux
Yukihiro M. (Guest)
on 2006-02-20 02:52
(Received via mailing list)
Hi,

In message "Re: Odd break behavior?"
    on Sun, 19 Feb 2006 03:02:04 +0900, ts 
<removed_email_address@domain.invalid>
writes:

|-static unsigned long block_unique = 0;
|+static unsigned long block_unique = 1;

| no ?

Yes!  You must be a genius.  Thank you.

							matz.
Yukihiro M. (Guest)
on 2006-02-20 03:01
(Received via mailing list)
Hi,

In message "Re: Odd break behavior?"
    on Sun, 19 Feb 2006 02:14:37 +0900, Thomas E Enebo 
<removed_email_address@domain.invalid>
writes:

|  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.
This topic is locked and can not be replied to.